getProtections example


        $fields = $definition->getFields();

        $properties = [];
        foreach ($fields as $field) {
            $properties[$field->getPropertyName()] = $this->parseField($definition$field);
        }

        $result = [
            'entity' => $definition->getEntityName(),
            'properties' => $properties,
            'write-protected' => $definition->getProtections()->get(WriteProtection::class) !== null,
            'read-protected' => $definition->getProtections()->get(ReadProtection::class) !== null,
        ];

        if ($definition instanceof DynamicEntityDefinition) {
            $result['flags'] = $definition->getFlags();
        }

        return $result;
    }

    /** * @return array{type: string, flags: array<string, mixed>} */
/** * @param list<array{entity: string, value: string|null, definition: EntityDefinition, field: Field|null}> $pathSegments * @param array<string> $protections FQCN of the protections that need to be validated */
    public function validateEntityPath(array $pathSegments, array $protections, Context $context): void
    {
        foreach ($pathSegments as $pathSegment) {
            /** @var EntityDefinition $definition */
            $definition = $pathSegment['definition'];

            foreach ($protections as $protection) {
                $protectionInstance = $definition->getProtections()->get($protection);
                if (!$protectionInstance || $protectionInstance->isAllowed($context->getScope())) {
                    continue;
                }

                throw new AccessDeniedHttpException(
                    sprintf('API access for entity "%s" not allowed.', $pathSegment['entity'])
                );
            }
        }
    }

    
Home | Imprint | This part of the site doesn't use cookies.