当前位置: 首页>>代码示例>>PHP>>正文


PHP Serializer::getMetadataFactory方法代码示例

本文整理汇总了PHP中JMS\Serializer\Serializer::getMetadataFactory方法的典型用法代码示例。如果您正苦于以下问题:PHP Serializer::getMetadataFactory方法的具体用法?PHP Serializer::getMetadataFactory怎么用?PHP Serializer::getMetadataFactory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在JMS\Serializer\Serializer的用法示例。


在下文中一共展示了Serializer::getMetadataFactory方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: apply

 /**
  * Stores the object in the request.
  *
  * @param Request        $request       The request
  * @param ParamConverter $configuration Contains the name, class and options of the object
  *
  * @throws \InvalidArgumentException
  *
  * @return bool True if the object has been successfully set, else false
  */
 public function apply(Request $request, ParamConverter $configuration)
 {
     $name = $configuration->getName();
     $class = $configuration->getClass();
     $options = $configuration->getOptions();
     if (isset($options['query'])) {
         $content = new \stdClass();
         $metadata = $this->serializer->getMetadataFactory()->getMetadataForClass($class);
         foreach ($metadata->propertyMetadata as $propertyMetadata) {
             if (!$propertyMetadata->readOnly) {
                 $property = $propertyMetadata->name;
                 $value = $request->query->get($propertyMetadata->name);
                 if (!is_null($value)) {
                     $content->{$property} = $request->query->get($propertyMetadata->name);
                 }
             }
         }
         $content = json_encode($content);
     } else {
         $content = $request->getContent();
     }
     if (!class_exists($class)) {
         throw new \InvalidArgumentException($class . ' class does not exist.');
     }
     $success = false;
     try {
         $model = $this->serializer->deserialize($content, $class, 'json');
         $success = true;
     } catch (\Exception $e) {
         $model = new $class();
     }
     /**
      * Validate if possible
      */
     if ($model instanceof ValidatableInterface) {
         $violations = $this->validator->validate($model);
         $valid = $success && !(bool) $violations->count();
         $model->setViolations($violations);
         $model->setValid($valid);
     }
     /**
      * Adding transformed collection
      * to request attribute.
      */
     $request->attributes->set($name, $model);
     /**
      * Alias to access current collection
      * Used by exception listener
      */
     $request->attributes->set(Alias::DATA, $name);
     return true;
 }
开发者ID:RomanShumkov,项目名称:EcentriaRestBundle,代码行数:62,代码来源:ModelConverter.php

示例2: __construct

 public function __construct(Serializer $serializer, array $bestReferencedFieldChoices)
 {
     $this->metadataFactory = $serializer->getMetadataFactory();
     $this->bestReferencedFieldChoices = $bestReferencedFieldChoices;
 }
开发者ID:rlamarche,项目名称:NgAdminGeneratorBundle,代码行数:5,代码来源:ReferencedFieldGuesser.php

示例3: __construct

 public function __construct(Serializer $serializer, PropertyNamingStrategyInterface $namingStrategy)
 {
     $this->metadataFactory = $serializer->getMetadataFactory();
     $this->namingStrategy = $namingStrategy;
 }
开发者ID:Djakson,项目名称:NgAdminGeneratorBundle,代码行数:5,代码来源:ClassNameToNgAdminConfigurationTransformer.php


注:本文中的JMS\Serializer\Serializer::getMetadataFactory方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。