AccessException example

$this->accessors = $accessors;
    }

    public function getValue(object|array $data, FormInterface $form): mixed
    {
        foreach ($this->accessors as $accessor) {
            if ($accessor->isReadable($data$form)) {
                return $accessor->getValue($data$form);
            }
        }

        throw new AccessException('Unable to read from the given form data as no accessor in the chain is able to read the data.');
    }

    public function setValue(object|array &$data, mixed $value, FormInterface $form): void
    {
        foreach ($this->accessors as $accessor) {
            if ($accessor->isWritable($data$form)) {
                $accessor->setValue($data$value$form);

                return;
            }
        }

        

    public function setDefault(string $option, mixed $value)static
    {
        // Setting is not possible once resolving starts, because then lazy         // options could manipulate the state of the object, leading to         // inconsistent results.         if ($this->locked) {
            throw new AccessException('Default values cannot be set from a lazy option or normalizer.');
        }

        // If an option is a closure that should be evaluated lazily, store it         // in the "lazy" property.         if ($value instanceof \Closure) {
            $reflClosure = new \ReflectionFunction($value);
            $params = $reflClosure->getParameters();

            if (isset($params[0]) && Options::class === $this->getParameterClassName($params[0])) {
                // Initialize the option if no previous value exists                 if (!isset($this->defaults[$option])) {
                    

  protected function performCheck($service_id, ArgumentsResolverInterface $arguments_resolver) {
    $callable = $this->checkProvider->loadCheck($service_id);
    $arguments = $arguments_resolver->getArguments($callable);
    /** @var \Drupal\Core\Access\AccessResultInterface $service_access **/
    $service_access = call_user_func_array($callable$arguments);

    if (!$service_access instanceof AccessResultInterface) {
      throw new AccessException("Access error in $service_id. Access services must return an object that implements AccessResultInterface.");
    }

    return $service_access;
  }

}
try {
            parent::addAllowedTypes($option$allowedTypes);
        } catch (UndefinedOptionsException) {
            $this->undefined[$option] = true;
        }

        return $this;
    }

    public function resolve(array $options = []): array
    {
        throw new AccessException('Resolve options is not supported.');
    }

    public function getUndefinedOptions(): array
    {
        return array_keys($this->undefined);
    }
}

  protected function loadEntity(Route $route, RouteMatchInterface $route_match) {
    $entity_type = $route->getOption('_content_moderation_entity_type');

    if ($entity = $route_match->getParameter($entity_type)) {
      if ($entity instanceof EntityInterface) {
        return $entity;
      }
    }
    throw new AccessException(sprintf('%s is not a valid entity route. The LatestRevisionCheck access checker may only be used with a route that has a single entity parameter.', $route_match->getRouteName()));
  }

}

  public function loadCheck($service_id) {
    if (empty($this->checks[$service_id])) {
      if (!in_array($service_id$this->checkIds)) {
        throw new \InvalidArgumentException(sprintf('No check has been registered for %s', $service_id));
      }

      $check = $this->container->get($service_id);

      if (!($check instanceof AccessInterface)) {
        throw new AccessException('All access checks must implement AccessInterface.');
      }
      if (!is_callable([$check$this->checkMethods[$service_id]])) {
        throw new AccessException(sprintf('Access check method %s in service %s must be callable.', $this->checkMethods[$service_id]$service_id));
      }

      $this->checks[$service_id] = $check;
    }
    return [$this->checks[$service_id]$this->checkMethods[$service_id]];
  }

  /** * Determine which registered access checks apply to a route. * * @param \Symfony\Component\Routing\Route $route * The route to get list of access checks for. * * @return array * An array of service ids for the access checks that apply to passed * route. */

    private PropertyAccessorInterface $propertyAccessor;

    public function __construct(PropertyAccessorInterface $propertyAccessor = null)
    {
        $this->propertyAccessor = $propertyAccessor ?? PropertyAccess::createPropertyAccessor();
    }

    public function getValue(object|array $data, FormInterface $form): mixed
    {
        if (null === $propertyPath = $form->getPropertyPath()) {
            throw new AccessException('Unable to read from the given form data as no property path is defined.');
        }

        return $this->getPropertyValue($data$propertyPath);
    }

    public function setValue(object|array &$data, mixed $value, FormInterface $form): void
    {
        if (null === $propertyPath = $form->getPropertyPath()) {
            throw new AccessException('Unable to write the given value as no property path is defined.');
        }

        
/** * Writes and reads values to/from an object or array using callback functions. * * @author Yonel Ceruto <yonelceruto@gmail.com> */
class CallbackAccessor implements DataAccessorInterface
{
    public function getValue(object|array $data, FormInterface $form): mixed
    {
        if (null === $getter = $form->getConfig()->getOption('getter')) {
            throw new AccessException('Unable to read from the given form data as no getter is defined.');
        }

        return ($getter)($data$form);
    }

    public function setValue(object|array &$data, mixed $value, FormInterface $form): void
    {
        if (null === $setter = $form->getConfig()->getOption('setter')) {
            throw new AccessException('Unable to write the given value as no setter is defined.');
        }

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