Пример #1
0
 /**
  * Process for listen message
  *
  * @param mixed $message
  *
  * @return bool
  *
  * @throws JsonParseException
  * @throws MissingMessagePropertyException
  * @throws UndefinedClassForReceiveException
  */
 protected function doListen($message)
 {
     // Try decode message (JSON)
     $message = @json_decode($message, true);
     if (null === $message || false === $message) {
         // Decode fail
         throw JsonParseException::create(json_last_error());
     }
     if (empty($message['name'])) {
         // Missing requires parameter
         throw new MissingMessagePropertyException('Missing requires parameter "name" in message.');
     }
     if (!isset($message['data'])) {
         // Missing requires parameter
         throw new MissingMessagePropertyException('Missing requires parameter "data" in message.');
     }
     $eventName = $message['name'];
     // Try get class for event
     $class = $this->listens->getClassNameForEvent($eventName);
     if (!$class) {
         throw new UndefinedClassForReceiveException(sprintf('Undefined class for receive notification by name "%s".', $eventName));
     }
     // Try recreate object from class
     $object = $this->objectRecreator->recreate($class, $message['data']);
     return $this->processor->process($eventName, $object);
 }
Пример #2
0
 /**
  * Process API method
  *
  * @param SfRequest $request
  *
  * @return JsonResponse
  *
  * @throws \Exception
  */
 private function processApiMethod(SfRequest $request)
 {
     // Try parse JSON
     $content = $request->getContent();
     if (!$content) {
         throw new MissingHttpContentException('Missing HTTP content.');
     }
     $query = @json_decode($content, true);
     if (false === $query) {
         throw JsonParseException::create(json_last_error());
     }
     return $this->processApiQuery($query);
 }