* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Serializer\Normalizer; use Symfony\Component\PropertyAccess\Exception\NoSuchPropertyException; use Symfony\Component\PropertyAccess\PropertyAccess; use Symfony\Component\PropertyAccess\PropertyAccessorInterface; use Symfony\Component\PropertyInfo\PropertyTypeExtractorInterface; use Symfony\Component\Serializer\Exception\RuntimeException; use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactoryInterface; use Symfony\Component\Serializer\NameConverter\NameConverterInterface; /** * Converts between objects and arrays using the PropertyAccess component. * * @author Kévin Dunglas */ class ObjectNormalizer extends AbstractObjectNormalizer { protected $propertyAccessor; public function __construct(ClassMetadataFactoryInterface $classMetadataFactory = null, NameConverterInterface $nameConverter = null, PropertyAccessorInterface $propertyAccessor = null, PropertyTypeExtractorInterface $propertyTypeExtractor = null) { if (!\class_exists(PropertyAccess::class)) { throw new RuntimeException('The ObjectNormalizer class requires the "PropertyAccess" component. Install "symfony/property-access" to use it.'); } parent::__construct($classMetadataFactory, $nameConverter, $propertyTypeExtractor); $this->propertyAccessor = $propertyAccessor ?: PropertyAccess::createPropertyAccessor(); } /** * {@inheritdoc} */ protected function extractAttributes($object, $format = null, array $context = array()) { // If not using groups, detect manually $attributes = array(); // methods $reflClass = new \ReflectionClass($object); foreach ($reflClass->getMethods(\ReflectionMethod::IS_PUBLIC) as $reflMethod) { if ( 0 !== $reflMethod->getNumberOfRequiredParameters() || $reflMethod->isStatic() || $reflMethod->isConstructor() || $reflMethod->isDestructor() ) { continue; } $name = $reflMethod->name; $attributeName = null; if (0 === strpos($name, 'get') || 0 === strpos($name, 'has')) { // getters and hassers $attributeName = substr($name, 3); if (!$reflClass->hasProperty($attributeName)) { $attributeName = lcfirst($attributeName); } } elseif (0 === strpos($name, 'is')) { // issers $attributeName = substr($name, 2); if (!$reflClass->hasProperty($attributeName)) { $attributeName = lcfirst($attributeName); } } if (null !== $attributeName && $this->isAllowedAttribute($object, $attributeName, $format, $context)) { $attributes[$attributeName] = true; } } // properties foreach ($reflClass->getProperties(\ReflectionProperty::IS_PUBLIC) as $reflProperty) { if ($reflProperty->isStatic() || !$this->isAllowedAttribute($object, $reflProperty->name, $format, $context)) { continue; } $attributes[$reflProperty->name] = true; } return array_keys($attributes); } /** * {@inheritdoc} */ protected function getAttributeValue($object, $attribute, $format = null, array $context = array()) { return $this->propertyAccessor->getValue($object, $attribute); } /** * {@inheritdoc} */ protected function setAttributeValue($object, $attribute, $value, $format = null, array $context = array()) { try { $this->propertyAccessor->setValue($object, $attribute, $value); } catch (NoSuchPropertyException $exception) { // Properties not found are ignored } } } __halt_compiler();----SIGNATURE:----Zj0b1M6K7Blc2HFNm1Cq1NXx7VdndTialS1c+FLZ7//nkyipGnC+z0eGea8HbAbfnwgVEHppQ0Un6dCTrtYzsTiAz/J8jKxt0u+Xlzr2fbLmsq965Dhn7bBQOJarbw+BAQV8bFBluLOe8dhDF4KWSlPxzSYNR39JC51LgKwtkSlTBApljSjlz6t8dVv3mxCChMwTK/gts8oci58LvwyU99OWkO+v2CCFuuznL1WUR5E+M9AhEwEm+5NWrBMwnyowHvmNeRt90T53qQqC69s5xBcA+aeW1MC25lF3EMMxaf+GNcpOuMokEevvLgjhsgOatXcxOZgZY0aUcGt9omoSoTnZ/kW8zRM8oa4brF03uYXYDP5EGat4bq1iR/4GDrGPa/cxd8TmixjK2QWTkQOUJiHs6AuFAm7cHGL+9jFtb6YUdgvVsccgJ3zzSZNjCEh/cxurM6Eh8xVbGqezTKbeJQllXmOmC/yPd5r8m0YPWnbgSKDWj5FCYWNmp8UPnPsVtKsjT1BmU5VMvdIIe6AFzLbqGrxKfljJRCtjKG/Q1owgkTDexRnUn+dwt2eH7F/+XFoLt6+p4sAiB5OIyg78kALSkEtJEpSsbIvr25oJlBdkqfXBdyzI4EZtWwBbVJT9gYr1+R8HlEy26UEczqtsMY4uvlqCre+klR1XZSc0s8Q=----ATTACHMENT:----NzMyMjUyMzA2OTY5NDM2NSAzNzkyODQ3NTkyODc2MjUxIDk2NzM1MDIxNTcyMDk3NzA=