Esempio n. 1
0
 /**
  * @param mixed $object
  * @return array
  */
 public function unmapObject($object)
 {
     if (is_array($object)) {
         return $object;
     }
     return $this->serializer->toArray($object);
 }
 /** @test */
 public function it_serializes_objects()
 {
     $object = new \stdClass();
     $this->serializer->toArray($object, Argument::any())->willReturn(['key' => 'value']);
     $data = $this->converter->toArray($object);
     $this->assertEquals(['event' => ['name' => 'stdClass', 'data' => ['key' => 'value']]], $data);
 }
Esempio n. 3
0
 /**
  * @param $procedureName
  * @param $arguments
  * @return \React\Promise\Promise
  */
 public function call($procedureName, $arguments, $argumentsKw = [], $options = null)
 {
     $arguments = $arguments ?: [$arguments];
     $argumentsKw = $argumentsKw ?: [$argumentsKw];
     $arguments = $this->serializer->toArray($arguments);
     $argumentsKw = $this->serializer->toArray($argumentsKw);
     //If we already have a client open that we can use, use that
     if ($this->container->initialized('wamp_kernel') && ($client = $this->container->get('wamp_kernel')->getClient())) {
         $session = $this->container->get('wamp_kernel')->getSession();
         return $session->call($procedureName, $arguments, $argumentsKw, $options);
     }
     Logger::set(new NullLogger());
     //So logs don't show up on the web page
     //If we don't already have a long running client, get a short lived one.
     $client = $this->getShortClient();
     $deferrer = new Deferred();
     $client->on("open", function (ClientSession $session, TransportInterface $transport) use($deferrer, $procedureName, $arguments, $argumentsKw, $options) {
         $session->call($procedureName, $arguments, $argumentsKw, $options)->then(function ($res) use($deferrer, $transport) {
             $transport->close();
             $deferrer->resolve($res);
         });
     });
     $client->on("error", function ($error) use($procedureName) {
         $this->container->get('logger')->addError("Got the following error when trying to call '{$procedureName}': {$error}");
         throw new \Exception("Got the following error when trying to call '{$procedureName}': {$error}");
     });
     $client->start();
     return $deferrer->promise();
 }
Esempio n. 4
0
 /**
  * Run the RPC result through JMS serializer, so that entities get serialized properly
  *
  * @param $rawResult
  * @param $mapping
  * @return mixed|static
  */
 protected function serializeResult($rawResult, $mapping)
 {
     //Create a serialization context
     $context = $this->createSerializationContext($mapping);
     if ($rawResult instanceof Promise) {
         return $rawResult->then(function ($d) use($context) {
             //If the data is a CallResult, we only want to serialize the first argument
             $d = $d instanceof CallResult ? [$d[0]] : $d;
             return $this->serializer->toArray($d, $context);
         });
     } elseif ($rawResult !== null) {
         return $this->serializer->toArray($rawResult, $context);
     }
 }
 private function convert($object)
 {
     return ['event' => ['name' => $this->getClassName($object), 'data' => $this->serializer->toArray($object, SerializationContext::create()->setSerializeNull(true))]];
 }
 /**
  * {@inheritdoc}
  */
 public function getAttributes($model, array $fields = null)
 {
     return $this->serializer->toArray($model);
 }