/**
  * Send all notification messages starting from the given ID
  *
  * @param  int                                                                $firstMessageId
  * @param  string                                                             $apnURL
  * @throws \RuntimeException
  * @throws \RMS\PushNotificationsBundle\Exception\InvalidMessageTypeException
  * @return int
  */
 protected function sendMessages($firstMessageId, $apnURL)
 {
     $errors = array();
     // Loop through all messages starting from the given ID
     for ($currentMessageId = $firstMessageId; $currentMessageId < count($this->messages); $currentMessageId++) {
         // Send the message
         $result = $this->writeApnStream($apnURL, $this->messages[$currentMessageId]);
         $errors = array();
         // Check if there is an error result
         if (is_array($result)) {
             // Close the apn stream in case of Shutdown status code.
             if ($result['status'] === self::APNS_SHUTDOWN_CODE) {
                 $this->closeApnStream($apnURL);
             }
             $this->responses[] = $result;
             // Resend all messages that were sent after the failed message
             $this->sendMessages($result['identifier'] + 1, $apnURL);
             $errors[] = $result;
             if ($this->logger) {
                 $this->logger->err(json_encode($result));
             }
         } else {
             $this->responses[] = true;
         }
     }
     return $errors;
 }
 public function send(MessageInterface $message)
 {
     if (!$message instanceof WindowsphoneMessage) {
         throw new InvalidMessageTypeException(sprintf("Message type '%s' not supported by MPNS", get_class($message)));
     }
     $headers = array('Content-Type: text/xml', 'X-WindowsPhone-Target: ' . $message->getTarget(), 'X-NotificationClass: ' . $message->getNotificationClass());
     $xml = new \SimpleXMLElement('<?xml version="1.0" encoding="utf-8"?><wp:Notification xmlns:wp="WPNotification" />');
     $msgBody = $message->getMessageBody();
     if ($message->getTarget() == WindowsphoneMessage::TYPE_TOAST) {
         $toast = $xml->addChild('wp:Toast');
         $toast->addChild('wp:Text1', htmlspecialchars($msgBody['text1'], ENT_XML1 | ENT_QUOTES));
         $toast->addChild('wp:Text2', htmlspecialchars($msgBody['text2'], ENT_XML1 | ENT_QUOTES));
     }
     $response = $this->browser->post($message->getDeviceIdentifier(), $headers, $xml->asXML());
     if (!$response->isSuccessful()) {
         $this->logger->err($response->getStatusCode() . ' : ' . $response->getReasonPhrase());
     }
     return $response->isSuccessful();
 }
 /**
  * Validate the command input options
  * Validate the dates and currency codes, if these are not valid then return with false.
  *
  * @param mixin $inputOptions
  * @param Logger $this->logger
  * @param Symfony\Component\Console\Output\OutputInterface $output
  * @return boolean|mixin return false if the command options are not valid else return with options
  */
 protected function validateCommandOptions($inputOptions, $output)
 {
     $options = array();
     $this->logger = $this->getContainer()->get('logger');
     if ($inputOptions['start']) {
         if (!Utils::validateDate($inputOptions['start'], 'Y-m-d')) {
             $output->writeln('<error>The start date is invalid:</error> ' . $inputOptions['start'] . '. <comment>Correct format:</comment> 2014-01-20');
             $this->logger->alert(sprintf('[|%s] The start option is in invalid date format.', Utils::getClassBasename($this)));
             exit(0);
         }
         $options['startDate'] = $inputOptions['start'];
     } else {
         // If the start option is missing and the it wasn't marked as a required options.
         if (!(isset($this->isNotRequiredOptions['start']) && true === $this->isNotRequiredOptions['start'])) {
             $output->writeln('<error>The start date is misssing</error>.' . 'Please use the <comment>--start</comment> option');
             $this->logger->error(sprintf('[|%s] The start option is missing.', Utils::getClassBasename($this)));
             exit(0);
         }
     }
     if ($inputOptions['end']) {
         if (!Utils::validateDate($inputOptions['end'], 'Y-m-d')) {
             $output->writeln('<error>The end date is invalid:</error> ' . $inputOptions['end'] . '. <comment>Correct format:</comment> 2014-01-20');
             $this->logger->alert(sprintf('[|%s] The end option is in invalid date format.', Utils::getClassBasename($this)));
             exit(0);
         }
         $options['endDate'] = $inputOptions['end'];
     }
     if ($inputOptions['currency']) {
         if (!Utils::validateCurrencyCodesString($inputOptions['currency'])) {
             $output->writeln('<error>The currency codes are invalid:</error> ' . $inputOptions['currency'] . '. <comment>Correct format:</comment> EUR,USD');
             $this->logger->alert(sprintf('[|%s] The currency option is in invalid format.', Utils::getClassBasename($this)));
             exit(0);
         }
         $options['currencyNames'] = strtoupper($inputOptions['currency']);
     }
     return $options;
 }
 /**
  * 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
  */
 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()));
     // Chunk number of registration IDs according to the maximum allowed by GCM
     $chunks = array_chunk($message->getGCMIdentifiers(), $this->registrationIdMaxCount);
     // Perform the calls (in parallel)
     $this->responses = array();
     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->err($response->getContent());
             } else {
                 $this->logger->err($message->failure);
             }
             return false;
         }
     }
     return true;
 }
 /**
  * Gets the 'monolog.logger.templating' service.
  *
  * This service is shared.
  * This method always returns the same instance of the service.
  *
  * @return \Symfony\Bridge\Monolog\Logger A Symfony\Bridge\Monolog\Logger instance.
  */
 protected function getMonolog_Logger_TemplatingService()
 {
     $this->services['monolog.logger.templating'] = $instance = new \Symfony\Bridge\Monolog\Logger('templating');
     $instance->pushHandler($this->get('monolog.handler.main'));
     $instance->pushHandler($this->get('monolog.handler.console'));
     $instance->pushHandler($this->get('monolog.handler.debug'));
     return $instance;
 }
 protected function getMonolog_Logger_SecurityService()
 {
     $this->services['monolog.logger.security'] = $instance = new \Symfony\Bridge\Monolog\Logger('security');
     $instance->pushHandler($this->get('monolog.handler.console'));
     $instance->pushHandler($this->get('monolog.handler.main'));
     return $instance;
 }
 protected function getMonolog_Logger_TranslationService()
 {
     $this->services['monolog.logger.translation'] = $instance = new \Symfony\Bridge\Monolog\Logger('translation');
     $instance->pushHandler($this->get('monolog.handler.main'));
     return $instance;
 }
 /**
  * Gets the 'monolog.logger.translation' service.
  *
  * This service is shared.
  * This method always returns the same instance of the service.
  *
  * @return \Symfony\Bridge\Monolog\Logger A Symfony\Bridge\Monolog\Logger instance
  */
 protected function getMonolog_Logger_TranslationService()
 {
     $this->services['monolog.logger.translation'] = $instance = new \Symfony\Bridge\Monolog\Logger('translation');
     $instance->pushProcessor(${($_ = isset($this->services['debug.log_processor']) ? $this->services['debug.log_processor'] : $this->getDebug_LogProcessorService()) && false ?: '_'});
     $instance->pushHandler($this->get('monolog.handler.console'));
     $instance->pushHandler($this->get('monolog.handler.main'));
     return $instance;
 }
 /**
  * Gets the 'vitacora.siig' service.
  *
  * This service is shared.
  * This method always returns the same instance of the service.
  *
  * @return \Symfony\Bridge\Monolog\Logger A Symfony\Bridge\Monolog\Logger instance.
  */
 protected function getVitacora_SiigService()
 {
     $this->services['vitacora.siig'] = $instance = new \Symfony\Bridge\Monolog\Logger('ACTIVIDAD');
     $instance->pushHandler($this->get('monolog.handler.vitacora.siig'));
     return $instance;
 }
 protected function getMonolog_Logger_SncRedisService()
 {
     $this->services['monolog.logger.snc_redis'] = $instance = new \Symfony\Bridge\Monolog\Logger('snc_redis');
     $instance->pushHandler($this->get('monolog.handler.main'));
     return $instance;
 }