コード例 #1
0
ファイル: DataMapper.php プロジェクト: raphhh/balloon
 /**
  * @param array $data
  * @return mixed
  */
 public function mapData(array $data)
 {
     if (!$this->getClassName()) {
         return $data;
     }
     return $this->serializer->fromArray($data, $this->getClassName());
 }
コード例 #2
0
 /**
  * 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
0
 /**
  * {@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;
 }