本文整理汇总了PHP中JMS\Serializer\Serializer::toArray方法的典型用法代码示例。如果您正苦于以下问题:PHP Serializer::toArray方法的具体用法?PHP Serializer::toArray怎么用?PHP Serializer::toArray使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JMS\Serializer\Serializer
的用法示例。
在下文中一共展示了Serializer::toArray方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: unmapObject
/**
* @param mixed $object
* @return array
*/
public function unmapObject($object)
{
if (is_array($object)) {
return $object;
}
return $this->serializer->toArray($object);
}
示例2: it_serializes_objects
/** @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);
}
示例3: call
/**
* @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();
}
示例4: serializeResult
/**
* 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);
}
}
示例5: convert
private function convert($object)
{
return ['event' => ['name' => $this->getClassName($object), 'data' => $this->serializer->toArray($object, SerializationContext::create()->setSerializeNull(true))]];
}
示例6: getAttributes
/**
* {@inheritdoc}
*/
public function getAttributes($model, array $fields = null)
{
return $this->serializer->toArray($model);
}