Symfony\Component\Serializer\Normalizer\AbstractNormalizer::getAllowedAttributes PHP Метод

getAllowedAttributes() защищенный Метод

Gets attributes to normalize using groups.
protected getAllowedAttributes ( string | object $classOrObject, array $context, boolean $attributesAsString = false ) : string[] | Symfony\Component\Serializer\Mapping\AttributeMetadataInterface[] | boolean
$classOrObject string | object
$context array
$attributesAsString boolean If false, return an array of {@link AttributeMetadataInterface}
Результат string[] | Symfony\Component\Serializer\Mapping\AttributeMetadataInterface[] | boolean
    protected function getAllowedAttributes($classOrObject, array $context, $attributesAsString = false)
    {
        if (!$this->classMetadataFactory || !isset($context[static::GROUPS]) || !is_array($context[static::GROUPS])) {
            return false;
        }
        $allowedAttributes = array();
        foreach ($this->classMetadataFactory->getMetadataFor($classOrObject)->getAttributesMetadata() as $attributeMetadata) {
            $name = $attributeMetadata->getName();
            if (count(array_intersect($attributeMetadata->getGroups(), $context[static::GROUPS])) && $this->isAllowedAttribute($classOrObject, $name, null, $context)) {
                $allowedAttributes[] = $attributesAsString ? $name : $attributeMetadata;
            }
        }
        return $allowedAttributes;
    }

Usage Example

 /**
  * {@inheritdoc}
  */
 public function getAllowedAttributes($classOrObject, array $context, $attributesAsString = false)
 {
     return parent::getAllowedAttributes($classOrObject, $context, $attributesAsString);
 }