Mercurial > hg > isophonics-drupal-site
comparison vendor/symfony/serializer/Normalizer/ObjectNormalizer.php @ 14:1fec387a4317
Update Drupal core to 8.5.2 via Composer
author | Chris Cannam |
---|---|
date | Mon, 23 Apr 2018 09:46:53 +0100 |
parents | 4c8ae668cc8c |
children | 129ea1e6d783 |
comparison
equal
deleted
inserted
replaced
13:5fb285c0d0e3 | 14:1fec387a4317 |
---|---|
13 | 13 |
14 use Symfony\Component\PropertyAccess\Exception\NoSuchPropertyException; | 14 use Symfony\Component\PropertyAccess\Exception\NoSuchPropertyException; |
15 use Symfony\Component\PropertyAccess\PropertyAccess; | 15 use Symfony\Component\PropertyAccess\PropertyAccess; |
16 use Symfony\Component\PropertyAccess\PropertyAccessorInterface; | 16 use Symfony\Component\PropertyAccess\PropertyAccessorInterface; |
17 use Symfony\Component\PropertyInfo\PropertyTypeExtractorInterface; | 17 use Symfony\Component\PropertyInfo\PropertyTypeExtractorInterface; |
18 use Symfony\Component\Serializer\Exception\RuntimeException; | |
18 use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactoryInterface; | 19 use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactoryInterface; |
19 use Symfony\Component\Serializer\NameConverter\NameConverterInterface; | 20 use Symfony\Component\Serializer\NameConverter\NameConverterInterface; |
20 | 21 |
21 /** | 22 /** |
22 * Converts between objects and arrays using the PropertyAccess component. | 23 * Converts between objects and arrays using the PropertyAccess component. |
23 * | 24 * |
24 * @author Kévin Dunglas <dunglas@gmail.com> | 25 * @author Kévin Dunglas <dunglas@gmail.com> |
25 */ | 26 */ |
26 class ObjectNormalizer extends AbstractObjectNormalizer | 27 class ObjectNormalizer extends AbstractObjectNormalizer |
27 { | 28 { |
28 /** | |
29 * @var PropertyAccessorInterface | |
30 */ | |
31 protected $propertyAccessor; | 29 protected $propertyAccessor; |
32 | 30 |
33 public function __construct(ClassMetadataFactoryInterface $classMetadataFactory = null, NameConverterInterface $nameConverter = null, PropertyAccessorInterface $propertyAccessor = null, PropertyTypeExtractorInterface $propertyTypeExtractor = null) | 31 public function __construct(ClassMetadataFactoryInterface $classMetadataFactory = null, NameConverterInterface $nameConverter = null, PropertyAccessorInterface $propertyAccessor = null, PropertyTypeExtractorInterface $propertyTypeExtractor = null) |
34 { | 32 { |
33 if (!\class_exists(PropertyAccess::class)) { | |
34 throw new RuntimeException('The ObjectNormalizer class requires the "PropertyAccess" component. Install "symfony/property-access" to use it.'); | |
35 } | |
36 | |
35 parent::__construct($classMetadataFactory, $nameConverter, $propertyTypeExtractor); | 37 parent::__construct($classMetadataFactory, $nameConverter, $propertyTypeExtractor); |
36 | 38 |
37 $this->propertyAccessor = $propertyAccessor ?: PropertyAccess::createPropertyAccessor(); | 39 $this->propertyAccessor = $propertyAccessor ?: PropertyAccess::createPropertyAccessor(); |
38 } | 40 } |
39 | 41 |
47 | 49 |
48 // methods | 50 // methods |
49 $reflClass = new \ReflectionClass($object); | 51 $reflClass = new \ReflectionClass($object); |
50 foreach ($reflClass->getMethods(\ReflectionMethod::IS_PUBLIC) as $reflMethod) { | 52 foreach ($reflClass->getMethods(\ReflectionMethod::IS_PUBLIC) as $reflMethod) { |
51 if ( | 53 if ( |
52 $reflMethod->getNumberOfRequiredParameters() !== 0 || | 54 0 !== $reflMethod->getNumberOfRequiredParameters() || |
53 $reflMethod->isStatic() || | 55 $reflMethod->isStatic() || |
54 $reflMethod->isConstructor() || | 56 $reflMethod->isConstructor() || |
55 $reflMethod->isDestructor() | 57 $reflMethod->isDestructor() |
56 ) { | 58 ) { |
57 continue; | 59 continue; |
65 $attributeName = substr($name, 3); | 67 $attributeName = substr($name, 3); |
66 | 68 |
67 if (!$reflClass->hasProperty($attributeName)) { | 69 if (!$reflClass->hasProperty($attributeName)) { |
68 $attributeName = lcfirst($attributeName); | 70 $attributeName = lcfirst($attributeName); |
69 } | 71 } |
70 } elseif (strpos($name, 'is') === 0) { | 72 } elseif (0 === strpos($name, 'is')) { |
71 // issers | 73 // issers |
72 $attributeName = substr($name, 2); | 74 $attributeName = substr($name, 2); |
73 | 75 |
74 if (!$reflClass->hasProperty($attributeName)) { | 76 if (!$reflClass->hasProperty($attributeName)) { |
75 $attributeName = lcfirst($attributeName); | 77 $attributeName = lcfirst($attributeName); |