public function send(MessageInterface $message)
    {
        if (!$message instanceof AndroidMessage) {
            throw new InvalidMessageTypeException(sprintf("Message type '%s' not supported by GCM", get_class($message)));
        }
        if (!$message->isGCM()) {
            throw new InvalidMessageTypeException("Non-GCM messages not supported by the Android GCM sender");
        }

        $headers = array(
            "Authorization: key=" . $this->apiKey,
            "Content-Type: application/json",
        );
        $data = array_merge(
            $message->getGCMOptions(),
            array("data" => $message->getData())
        );

        if ($this->useDryRun) {
            $data['dry_run'] = true;
        }

        // Perform the calls (in parallel)
        $this->responses = array();
        $gcmIdentifiers = $message->getGCMIdentifiers();

        if (count($message->getGCMIdentifiers()) == 1) {
            $data['to'] = $gcmIdentifiers[0];
            $this->responses[] = $this->browser->post($this->apiURL, $headers, json_encode($data));
        } else {
            // Chunk number of registration IDs according to the maximum allowed by GCM
            $chunks = array_chunk($message->getGCMIdentifiers(), $this->registrationIdMaxCount);

            foreach ($chunks as $registrationIDs) {
                $data['registration_ids'] = $registrationIDs;
                $this->responses[] = $this->browser->post($this->apiURL, $headers, json_encode($data));
            }
        }

        // If we're using multiple concurrent connections via MultiCurl
        // then we should flush all requests
        if ($this->browser->getClient() instanceof MultiCurl) {
            $this->browser->getClient()->flush();
        }

        // Determine success
        foreach ($this->responses as $response) {
            $message = json_decode($response->getContent());
            if ($message === null || $message->success == 0 || $message->failure > 0) {
                if ($message == null) {
                    $this->logger->error($response->getContent());
                } else {
                    foreach ($message->results as $result) {
                        if (isset($result->error)) {
                            $this->logger->error($result->error);
                        }
                    }
                }
                return false;
            }
        }

        return true;
    }
public function send(MessageInterface $message)
    {
        if (!$message instanceof AndroidMessage) {
            throw new InvalidMessageTypeException(sprintf("Message type '%s' not supported by GCM", get_class($message)));
        }
        if (!$message->isGCM()) {
            throw new InvalidMessageTypeException("Non-GCM messages not supported by the Android GCM sender");
        }

        $headers = array(
            "Authorization: key=" . $this->apiKey,
            "Content-Type: application/json",
        );
        $data = array_merge(
            $message->getGCMOptions(),
            array("data" => $message->getData())
        );

        if ($this->useDryRun) {
            $data['dry_run'] = true;
        }

        // Perform the calls (in parallel)
        $this->responses = array();
        $gcmIdentifiers = $message->getGCMIdentifiers();

        if (count($message->getGCMIdentifiers()) == 1) {
            $data['to'] = $gcmIdentifiers[0];
            $this->responses[] = $this->browser->post($this->apiURL, $headers, json_encode($data));
        } else {
            // Chunk number of registration IDs according to the maximum allowed by GCM
            $chunks = array_chunk($message->getGCMIdentifiers(), $this->registrationIdMaxCount);

            foreach ($chunks as $registrationIDs) {
                $data['registration_ids'] = $registrationIDs;
                $this->responses[] = $this->browser->post($this->apiURL, $headers, json_encode($data));
            }
        }

        // If we're using multiple concurrent connections via MultiCurl
        // then we should flush all requests
        if ($this->browser->getClient() instanceof MultiCurl) {
            $this->browser->getClient()->flush();
        }

        // Determine success
        foreach ($this->responses as $response) {
            $message = json_decode($response->getContent());
            if ($message === null || $message->success == 0 || $message->failure > 0) {
                if ($message == null) {
                    $this->logger->error($response->getContent());
                } else {
                    foreach ($message->results as $result) {
                        if (isset($result->error)) {
                            $this->logger->error($result->error);
                        }
                    }
                }
                return false;
            }
        }

        return true;
    }
public function send ( MessageInterface $ message ) { if ( ! $ message instanceof AndroidMessage ) { throw new InvalidMessageTypeException ( sprintf ( "Message type '%s' not supported by GCM" , get_class ( $ message ) ) ) ; } if ( ! $ message -> isGCM ( ) ) { throw new InvalidMessageTypeException ( "Non-GCM messages not supported by the Android GCM sender" ) ; } $ headers = array ( "Authorization: key=" . $ this -> apiKey , "Content-Type: application/json" , ) ; $ data = array_merge ( $ message -> getGCMOptions ( ) , array ( "data" => $ message -> getData ( ) ) ) ; if ( $ this -> useDryRun ) { $ data [ 'dry_run' ] = true ; } // Perform the calls (in parallel) $ this -> responses = array ( ) ; $ gcmIdentifiers = $ message -> getGCMIdentifiers ( ) ; if ( count ( $ message -> getGCMIdentifiers ( ) ) == 1 ) { $ data [ 'to' ] = $ gcmIdentifiers [ 0 ] ; $ this -> responses [ ] = $ this -> browser -> post ( $ this -> apiURL , $ headers , json_encode ( $ data ) ) ; } else { // Chunk number of registration IDs according to the maximum allowed by GCM $ chunks = array_chunk ( $ message -> getGCMIdentifiers ( ) , $ this -> registrationIdMaxCount ) ; foreach ( $ chunks as $ registrationIDs ) { $ data [ 'registration_ids' ] = $ registrationIDs ; $ this -> responses [ ] = $ this -> browser -> post ( $ this -> apiURL , $ headers , json_encode ( $ data ) ) ; } } // If we're using multiple concurrent connections via MultiCurl // then we should flush all requests if ( $ this -> browser -> getClient ( ) instanceof MultiCurl ) { $ this -> browser -> getClient ( ) -> flush ( ) ; } // Determine success foreach ( $ this -> responses as $ response ) { $ message = json_decode ( $ response -> getContent ( ) ) ; if ( $ message === null || $ message -> success == 0 || $ message -> failure > 0 ) { if ( $ message == null ) { $ this -> logger -> error ( $ response -> getContent ( ) ) ; } else { foreach ( $ message -> results as $ result ) { if ( isset ( $ result -> error ) ) { $ this -> logger -> error ( $ result -> error ) ; } } } return false ; } } return true ; }
Sends the data to the given registration IDs via the GCM server

@param  \RMS\PushNotificationsBundle\Message\MessageInterface              $message
@throws \RMS\PushNotificationsBundle\Exception\InvalidMessageTypeException
@return bool
Sends the data to the given registration IDs via the GCM server