本文整理匯總了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;
}
示例2: __construct
public function __construct(Serializer $serializer, array $bestReferencedFieldChoices)
{
$this->metadataFactory = $serializer->getMetadataFactory();
$this->bestReferencedFieldChoices = $bestReferencedFieldChoices;
}
示例3: __construct
public function __construct(Serializer $serializer, PropertyNamingStrategyInterface $namingStrategy)
{
$this->metadataFactory = $serializer->getMetadataFactory();
$this->namingStrategy = $namingStrategy;
}
開發者ID:Djakson,項目名稱:NgAdminGeneratorBundle,代碼行數:5,代碼來源:ClassNameToNgAdminConfigurationTransformer.php