Esempio n. 1
0
 /**
  * {@inheritdoc}
  *
  * @throws \Sly\NotificationPusher\Exception\PushException
  */
 public function push(PushInterface $push)
 {
     $client = $this->getOpenedServiceClient();
     $pushedDevices = new DeviceCollection();
     foreach ($push->getDevices() as $device) {
         $message = $this->getServiceMessageFromOrigin($device, $push->getMessage());
         try {
             $this->response = $client->send($message);
         } catch (ServiceRuntimeException $e) {
             throw new PushException($e->getMessage());
         }
         if (ServiceResponse::RESULT_OK === $this->response->getCode()) {
             $pushedDevices->add($device);
         }
     }
     return $pushedDevices;
 }
Esempio n. 2
0
 /**
  * {@inheritdoc}
  *
  * @throws \Sly\NotificationPusher\Exception\PushException
  */
 public function push(PushInterface $push)
 {
     $client = $this->getOpenedClient(new ServiceClient());
     $pushedDevices = new DeviceCollection();
     $tokens = array_chunk($push->getDevices()->getTokens(), 100);
     foreach ($tokens as $tokensRange) {
         $message = $this->getServiceMessageFromOrigin($tokensRange, $push->getMessage());
         try {
             $this->response = $client->send($message);
         } catch (ServiceRuntimeException $e) {
             throw new PushException($e->getMessage());
         }
         if ((bool) $this->response->getSuccessCount()) {
             foreach ($tokensRange as $token) {
                 $pushedDevices->add($push->getDevices()->get($token));
             }
         }
     }
     return $pushedDevices;
 }