Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Serializer] [WIP] Added annotations and MetadataAwareNormalizer #19374

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 13 commits into from
Prev Previous commit
Next Next commit
Added support for XML
  • Loading branch information
Nyholm committed Sep 2, 2018
commit 0e96e86491e6ecdd2d9cf519ada2bad03a1351f0
38 changes: 38 additions & 0 deletions 38 src/Symfony/Component/Serializer/Mapping/Loader/XmlFileLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,47 @@ public function loadClassMetadata(ClassMetadataInterface $classMetadata)
$attributeMetadata->addGroup((string) $group);
}

foreach ($attribute->methods as $methods) {
if (isset($methods['accessor'])) {
$attributeMetadata->setMethodsAccessor((string) $methods['accessor']);
}

if (isset($methods['mutator'])) {
$attributeMetadata->setMethodsMutator((string) $methods['mutator']);
}
}

if (isset($attribute['exclude'])) {
$attributeMetadata->setExclude((bool) $attribute['exclude']);
}

if (isset($attribute['expose'])) {
$attributeMetadata->setExpose((bool) $attribute['expose']);
}

if (isset($attribute['max-depth'])) {
$attributeMetadata->setMaxDepth((int) $attribute['max-depth']);
}

if (isset($attribute['read-only'])) {
$attributeMetadata->setReadOnly((bool) $attribute['read-only']);
}

if (isset($attribute['serialized-name'])) {
$attributeMetadata->setSerializedName((string) $attribute['serialized-name']);
}

if (isset($attribute['type'])) {
$attributeMetadata->setType((string) $attribute['type']);
}
}

if (isset($xml['exclusion-policy'])) {
$classMetadata->setExclusionPolicy((string) $xml['exclusion-policy']);
}

if (isset($xml['read-only'])) {
$classMetadata->setReadOnly((bool) $xml['read-only']);
}

if (isset($xml->{'discriminator-map'})) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ public function loadClassMetadata(ClassMetadataInterface $classMetadata)

$classMetadata->setExclusionPolicy($yaml['exclusion_policy']);
}

if (isset($yaml['read_only'])) {
if (!\is_bool($yaml['read_only'])) {
throw new MappingException(sprintf('The "read_only" value must be a boolean in "%s" for the class "%s".', $this->file, $classMetadata->getName()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ final class MetadataAwareNormalizer extends AbstractObjectNormalizer
*/
protected $propertyAccessor;

public function __construct(ClassMetadataFactoryInterface $classMetadataFactory = null, NameConverterInterface $nameConverter = null, PropertyTypeExtractorInterface $propertyTypeExtractor = null, ClassDiscriminatorResolverInterface $classDiscriminatorResolver = null, PropertyAccessorInterface $propertyAccessor = null) {
public function __construct(ClassMetadataFactoryInterface $classMetadataFactory = null, NameConverterInterface $nameConverter = null, PropertyTypeExtractorInterface $propertyTypeExtractor = null, ClassDiscriminatorResolverInterface $classDiscriminatorResolver = null, PropertyAccessorInterface $propertyAccessor = null)
{
if (null === $propertyAccessor) {
$propertyAccessor = PropertyAccess::createPropertyAccessor();
}
$this->propertyAccessor = $propertyAccessor;
parent::__construct($classMetadataFactory, $nameConverter, $propertyTypeExtractor, $classDiscriminatorResolver);
}


/**
* {@inheritdoc}
*/
Expand Down Expand Up @@ -173,7 +173,6 @@ protected function updateData(array $data, string $attribute, $attributeValue/*
}
$object = func_get_arg(3);


/** @var ClassMetadataInterface $classMetadata */
$classMetadata = $this->classMetadataFactory->getMetadataFor($object);
$attributeMetadata = $classMetadata->getAttributesMetadata();
Expand All @@ -198,10 +197,11 @@ protected function prepareForDenormalization($data/*, string $class*/)
{
if (1 === \func_num_args()) {
@trigger_error('Second argument to MetadataAwareNormalizer must be the class name', E_USER_DEPRECATED);

return (array) $data;
}

$class = func_get_arg(1);
$class = func_get_arg(1);
$preparedData = array();
$data = (array) $data;
/** @var ClassMetadataInterface $classMetadata */
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.