ApiPlatform\Core\Hal\Serializer\ItemNormalizer::getComponents PHP Метод

getComponents() приватный метод

Gets HAL components of the resource: states, links and embedded.
private getComponents ( object $object, string $format = null, array $context ) : array
$object object
$format string
$context array
Результат array
    private function getComponents($object, string $format = null, array $context)
    {
        if (isset($this->componentsCache[$context['cache_key']])) {
            return $this->componentsCache[$context['cache_key']];
        }
        $attributes = parent::getAttributes($object, $format, $context);
        $options = $this->getFactoryOptions($context);
        $components = ['states' => [], 'links' => [], 'embedded' => []];
        foreach ($attributes as $attribute) {
            $propertyMetadata = $this->propertyMetadataFactory->create($context['resource_class'], $attribute, $options);
            $type = $propertyMetadata->getType();
            $isOne = $isMany = false;
            if (null !== $type) {
                if ($type->isCollection()) {
                    $valueType = $type->getCollectionValueType();
                    $isMany = null !== $valueType && ($className = $valueType->getClassName()) && $this->resourceClassResolver->isResourceClass($className);
                } else {
                    $className = $type->getClassName();
                    $isOne = $className && $this->resourceClassResolver->isResourceClass($className);
                }
            }
            if (!$isOne && !$isMany) {
                $components['states'][] = $attribute;
                continue;
            }
            $relation = ['name' => $attribute, 'cardinality' => $isOne ? 'one' : 'many'];
            if ($propertyMetadata->isReadableLink()) {
                $components['embedded'][] = $relation;
            }
            $components['links'][] = $relation;
        }
        return $this->componentsCache[$context['cache_key']] = $components;
    }