本文整理汇总了PHP中JMS\Serializer\Serializer::fromArray方法的典型用法代码示例。如果您正苦于以下问题:PHP Serializer::fromArray方法的具体用法?PHP Serializer::fromArray怎么用?PHP Serializer::fromArray使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JMS\Serializer\Serializer
的用法示例。
在下文中一共展示了Serializer::fromArray方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: mapData
/**
* @param array $data
* @return mixed
*/
public function mapData(array $data)
{
if (!$this->getClassName()) {
return $data;
}
return $this->serializer->fromArray($data, $this->getClassName());
}
示例2: deserializeArgs
/**
* Deserialize Controller arguments
*
* //@todo add ability to configure the deserialization context
*
* @param $args
* @param MappingInterface $mapping
* @return array|bool
*/
private function deserializeArgs($args, MappingInterface $mapping)
{
try {
if ($this->isAssoc($args)) {
$args = [$args];
}
$deserializedArgs = [];
if ($mapping->getMethod()->getNumberOfRequiredParameters() > count($args)) {
throw new \Exception("Not enough parameters for '{$mapping->getMethod()->class}::{$mapping->getMethod()->getName()}'");
}
/* @var $params \ReflectionParameter[] */
$params = $mapping->getmethod()->getParameters();
foreach ($args as $key => $arg) {
$className = null;
if (isset($params[$key]) && $params[$key]->getClass() && $params[$key]->getClass()->getName()) {
if (!$params[$key]->getClass()->isInstantiable()) {
throw new \Exception("Can't deserialize to '{$params[$key]->getClass()->getName()}', because it is not instantiable.");
}
$args = is_array($args) ? $args : (array) $args;
$className = $params[$key]->getClass()->getName();
$deserializedArgs[] = $this->serializer->fromArray($arg, $className);
} else {
$deserializedArgs[] = $arg;
}
}
return $deserializedArgs;
} catch (\Exception $e) {
$this->logger->emergency($e->getMessage());
}
return [];
}
示例3: convert
/**
* {@inheritdoc}
*/
public function convert(ServiceReference $service, array $arguments)
{
foreach ($arguments as $name => $value) {
if (strpos($name, '__internal__') !== false) {
continue;
}
$parameter = $service->getParameter($name);
if (!$parameter || !is_array($value)) {
continue;
}
if (!$parameter->getClass()) {
continue;
}
$arguments[$name] = $this->serializer->fromArray($value, $parameter->getClass()->name, $this->createDeserializationContext($service, $name));
}
return $arguments;
}