src/Sly/NotificationPusher/GcmPushService.php
public function push(array $tokens = [], array $notifications = [], array $params = [])
    {
        if (!$tokens || !$notifications) {
            return null;
        }

        $adapterParams = [];
        $deviceParams  = [];
        $messageParams = [];
        if (isset($params) && !empty($params)) {
            if (isset($params['adapter'])) {
                $adapterParams = $params['adapter'];
            }

            if (isset($params['device'])) {
                $deviceParams = $params['device'];
            }

            if (isset($params['message'])) {
                $messageParams = $params['message'];
            }

            //because we have now notification and data separated
            if (isset($params['notificationData'])) {
                $messageParams['notificationData'] = $params['notificationData'];
            }
        }

        $adapterParams['apiKey'] = $this->apiKey;

        if (!$this->apiKey) {
            throw new \RuntimeException('Android api key must be set');
        }

        // Development one by default (without argument).
        /** @var PushManager $pushManager */
        $pushManager = new PushManager($this->environment);

        // Then declare an adapter.
        $gcmAdapter = new GcmAdapter($adapterParams);

        // Set the device(s) to push the notification to.
        $devices = new DeviceCollection([]);

        //devices
        foreach ($tokens as $token) {
            $devices->add(new Device($token, $deviceParams));
        }

        foreach ($notifications as $notificationText) {
            // Then, create the push skel.
            $message = new Message($notificationText, $messageParams);

            // Finally, create and add the push to the manager, and push it!
            $push = new Push($gcmAdapter, $devices, $message);
            $pushManager->add($push);
        }

        // Returns a collection of notified devices
        $pushes = $pushManager->push();

        $this->response = $gcmAdapter->getResponse();

        return $this->response;
    }
public function push(array $tokens = [], array $notifications = [], array $params = [])
    {
        if (!$tokens || !$notifications) {
            return null;
        }

        $adapterParams = [];
        $deviceParams  = [];
        $messageParams = [];
        if (isset($params) && !empty($params)) {
            if (isset($params['adapter'])) {
                $adapterParams = $params['adapter'];
            }

            if (isset($params['device'])) {
                $deviceParams = $params['device'];
            }

            if (isset($params['message'])) {
                $messageParams = $params['message'];
            }

            //because we have now notification and data separated
            if (isset($params['notificationData'])) {
                $messageParams['notificationData'] = $params['notificationData'];
            }
        }

        $adapterParams['apiKey'] = $this->apiKey;

        if (!$this->apiKey) {
            throw new \RuntimeException('Android api key must be set');
        }

        // Development one by default (without argument).
        /** @var PushManager $pushManager */
        $pushManager = new PushManager($this->environment);

        // Then declare an adapter.
        $gcmAdapter = new GcmAdapter($adapterParams);

        // Set the device(s) to push the notification to.
        $devices = new DeviceCollection([]);

        //devices
        foreach ($tokens as $token) {
            $devices->add(new Device($token, $deviceParams));
        }

        foreach ($notifications as $notificationText) {
            // Then, create the push skel.
            $message = new Message($notificationText, $messageParams);

            // Finally, create and add the push to the manager, and push it!
            $push = new Push($gcmAdapter, $devices, $message);
            $pushManager->add($push);
        }

        // Returns a collection of notified devices
        $pushes = $pushManager->push();

        $this->response = $gcmAdapter->getResponse();

        return $this->response;
    }
public function push ( array $ tokens = [ ] , array $ notifications = [ ] , array $ params = [ ] ) { if ( ! $ tokens || ! $ notifications ) { return null ; } $ adapterParams = [ ] ; $ deviceParams = [ ] ; $ messageParams = [ ] ; if ( isset ( $ params ) && ! empty ( $ params ) ) { if ( isset ( $ params [ 'adapter' ] ) ) { $ adapterParams = $ params [ 'adapter' ] ; } if ( isset ( $ params [ 'device' ] ) ) { $ deviceParams = $ params [ 'device' ] ; } if ( isset ( $ params [ 'message' ] ) ) { $ messageParams = $ params [ 'message' ] ; } //because we have now notification and data separated if ( isset ( $ params [ 'notificationData' ] ) ) { $ messageParams [ 'notificationData' ] = $ params [ 'notificationData' ] ; } } $ adapterParams [ 'apiKey' ] = $ this -> apiKey ; if ( ! $ this -> apiKey ) { throw new \ RuntimeException ( 'Android api key must be set' ) ; } // Development one by default (without argument). /** @var PushManager $pushManager */ $ pushManager = new PushManager ( $ this -> environment ) ; // Then declare an adapter. $ gcmAdapter = new GcmAdapter ( $ adapterParams ) ; // Set the device(s) to push the notification to. $ devices = new DeviceCollection ( [ ] ) ; //devices foreach ( $ tokens as $ token ) { $ devices -> add ( new Device ( $ token , $ deviceParams ) ) ; } foreach ( $ notifications as $ notificationText ) { // Then, create the push skel. $ message = new Message ( $ notificationText , $ messageParams ) ; // Finally, create and add the push to the manager, and push it! $ push = new Push ( $ gcmAdapter , $ devices , $ message ) ; $ pushManager -> add ( $ push ) ; } // Returns a collection of notified devices $ pushes = $ pushManager -> push ( ) ; $ this -> response = $ gcmAdapter -> getResponse ( ) ; return $ this -> response ; }
params keys
adapter
message
device

@param array $tokens
@param array $notifications
@param array $params
@return ResponseInterface
params keys adapter message device