* * 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:----on3D5EJzJoZGTsSkZFR9zeCiO6YO6Qz2mmeaovEwi+holUe4JDa7vJpwK5j5PHDrfIeRxehB0EhP73kD7MEDjoDdurnLQnAnmcQ+t5/ftlE0BtWEVRA1WiPPNdhvkaKAxcpWuNBNk635V531iotDmheOOtHE2qiwVfDPwepDLQ2gvh22chj/Lgzq6b28jn+3egp6ENjAdmFM3PC2tQk87VwmgONbQS9me3GwlrGHjKdYCJv0F2a5ufNZT8mKk9qmwGWFj2PVepao0+g3FTiwdyaX747BVpCBZNhztJoxyOjn/U+Q9hmDFBVWabYjKG1CHr9E5QKd+EttZpPYiisR+4GISIbzWl+ekBFFQqydMaZ544hnoI2TBqkEamWCeeOUHddSadCie6Dde434GEdBI81pX7HD1yeFkC4x9sKByi9xSSPU5nNWXFgV7yLzyTSi+yjFlpFDAFTVum3aIgjjMVZbKd1DXliDfJKieNH7uIrfLHGsRACXSLJMj5Y+C0BpD5JoF5Now9Gx9BJIiP/Y7lhHWCFVI7kZQUqyBYkviZ8EKFplOz3a1IP3trT5I9TNwf2LxN7KKV4n24H5bQOPod7G5lujiOhn3pDJIQihaCkoSDGKN3qe340waJL7AXGm/k4l7H2cTTXSwE86HljZYSTP+dBuu3ZkjuazgBMcC3U=----ATTACHMENT:----MTYxNDEwNjY5NzY4MjY4OCA1Nzg1NTM3MjA2OTMxNjM3IDI5MDkzNDI1NTkzNzMyNzI=