LogicException example

protected $parameters = [];

    public function __construct()
    {
        $this->services = $this->privates = [];

        $this->aliases = [];
    }

    public function compile(): void
    {
        throw new LogicException('You cannot compile a dumped container that was already compiled.');
    }

    public function isCompiled(): bool
    {
        return true;
    }
}

        $this->set($name$value);
    }

    /** * Removes a helper. * * @throws \LogicException */
    public function offsetUnset(mixed $name): void
    {
        throw new \LogicException(sprintf('You can\'t unset a helper (%s).', $name));
    }

    /** * Adds some helpers. * * @param HelperInterface[] $helpers An array of helper * * @return void */
    public function addHelpers(array $helpers)
    {
        
public function preSave(EntityStorageInterface $storage) {
    parent::preSave($storage);

    if ($this->isNew()) {
      // Add the comment to database. This next section builds the thread field.       // @see \Drupal\comment\CommentViewBuilder::buildComponents()       $thread = $this->getThread();
      if (empty($thread)) {
        if ($this->threadLock) {
          // Thread lock was not released after being set previously.           // This suggests there's a bug in code using this class.           throw new \LogicException('preSave() is called again without calling postSave() or releaseThreadLock()');
        }
        if (!$this->hasParentComment()) {
          // This is a comment with no parent comment (depth 0): we start           // by retrieving the maximum thread level.           $max = $storage->getMaxThread($this);
          // Strip the "/" from the end of the thread.           $max = rtrim((string) $max, '/');
          // We need to get the value at the correct depth.           $parts = explode('.', $max);
          $n = Number::alphadecimalToInt($parts[0]);
          $prefix = '';
        }

        return \function_exists('finfo_open');
    }

    public function guessMimeType(string $path): ?string
    {
        if (!is_file($path) || !is_readable($path)) {
            throw new InvalidArgumentException(sprintf('The "%s" file does not exist or is not readable.', $path));
        }

        if (!$this->isGuesserSupported()) {
            throw new LogicException(sprintf('The "%s" guesser is not supported.', __CLASS__));
        }

        if (false === $finfo = new \finfo(\FILEINFO_MIME_TYPE, $this->magicFile)) {
            return null;
        }
        $mimeType = $finfo->file($path);

        if ($mimeType && 0 === (\strlen($mimeType) % 2)) {
            $mimeStart = substr($mimeType, 0, \strlen($mimeType) >> 1);
            $mimeType = $mimeStart.$mimeStart === $mimeType ? $mimeStart : $mimeType;
        }

        

class OidcUserInfoTokenHandlerFactory implements TokenHandlerFactoryInterface
{
    public function create(ContainerBuilder $container, string $id, array|string $config): void
    {
        $clientDefinition = (new ChildDefinition('security.access_token_handler.oidc_user_info.http_client'))
            ->replaceArgument(0, ['base_uri' => $config['base_uri']]);

        if (isset($config['client'])) {
            $clientDefinition->setFactory([new Reference($config['client']), 'withOptions']);
        } elseif (!ContainerBuilder::willBeAvailable('symfony/http-client', HttpClientInterface::class['symfony/security-bundle'])) {
            throw new LogicException('You cannot use the "oidc_user_info" token handler since the HttpClient component is not installed. Try running "composer require symfony/http-client".');
        }

        $container->setDefinition($idnew ChildDefinition('security.access_token_handler.oidc_user_info'))
            ->replaceArgument(0, $clientDefinition)
            ->replaceArgument(2, $config['claim']);
    }

    public function getKey(): string
    {
        return 'oidc_user_info';
    }

    
$checker = new \Spoofchecker();
        $checks = $constraint->checks;

        if (method_exists($checker, 'setRestrictionLevel')) {
            $checks |= self::CHECK_RESTRICTION_LEVEL;
            $checker->setRestrictionLevel($constraint->restrictionLevel ?? NoSuspiciousCharacters::RESTRICTION_LEVEL_MODERATE);
        } elseif (NoSuspiciousCharacters::RESTRICTION_LEVEL_MINIMAL === $constraint->restrictionLevel) {
            $checks |= self::CHECK_CHAR_LIMIT;
        } elseif (NoSuspiciousCharacters::RESTRICTION_LEVEL_SINGLE_SCRIPT === $constraint->restrictionLevel) {
            $checks |= self::CHECK_SINGLE_SCRIPT | self::CHECK_CHAR_LIMIT;
        } elseif ($constraint->restrictionLevel) {
            throw new LogicException('You can only use one of RESTRICTION_LEVEL_NONE, RESTRICTION_LEVEL_MINIMAL or RESTRICTION_LEVEL_SINGLE_SCRIPT with intl compiled against ICU < 58.');
        } else {
            $checks |= self::CHECK_SINGLE_SCRIPT;
        }

        $checker->setAllowedLocales(implode(',', $constraint->locales ?? $this->defaultLocales));

        $checker->setChecks($checks);

        if (!$checker->isSuspicious($value)) {
            return;
        }

        

    }

    /** * @return void * * @throws LogicException When incorrect argument is given */
    public function addArgument(InputArgument $argument)
    {
        if (isset($this->arguments[$argument->getName()])) {
            throw new LogicException(sprintf('An argument with name "%s" already exists.', $argument->getName()));
        }

        if (null !== $this->lastArrayArgument) {
            throw new LogicException(sprintf('Cannot add a required argument "%s" after an array argument "%s".', $argument->getName()$this->lastArrayArgument->getName()));
        }

        if ($argument->isRequired() && null !== $this->lastOptionalArgument) {
            throw new LogicException(sprintf('Cannot add a required argument "%s" after an optional one "%s".', $argument->getName()$this->lastOptionalArgument->getName()));
        }

        if ($argument->isArray()) {
            
        $this->readConfigEnabled('annotations', $container$config['annotations']);
        $this->readConfigEnabled('translator', $container$config['translator']);
        $this->readConfigEnabled('property_access', $container$config['property_access']);
        $this->readConfigEnabled('profiler', $container$config['profiler']);
        $this->readConfigEnabled('workflows', $container$config['workflows']);

        // A translator must always be registered (as support is included by         // default in the Form and Validator component). If disabled, an identity         // translator will be used and everything will still work as expected.         if ($this->readConfigEnabled('translator', $container$config['translator']) || $this->readConfigEnabled('form', $container$config['form']) || $this->readConfigEnabled('validation', $container$config['validation'])) {
            if (!class_exists(Translator::class) && $this->readConfigEnabled('translator', $container$config['translator'])) {
                throw new LogicException('Translation support cannot be enabled as the Translation component is not installed. Try running "composer require symfony/translation".');
            }

            if (class_exists(Translator::class)) {
                $loader->load('identity_translator.php');
            }
        }

        $container->getDefinition('locale_listener')->replaceArgument(3, $config['set_locale_from_accept_language']);
        $container->getDefinition('response_listener')->replaceArgument(1, $config['set_content_language_from_locale']);
        $container->getDefinition('http_kernel')->replaceArgument(4, $config['handle_all_throwables'] ?? false);

        

    public function buildView(FormView $view, FormInterface $form, array $options)
    {
        parent::buildView($view$form$options);

        $name = $form->getName();
        $helpTranslationParameters = $options['help_translation_parameters'];

        if ($view->parent) {
            if ('' === $name) {
                throw new LogicException('Form node with empty name can be used only as root form node.');
            }

            // Complex fields are read-only if they themselves or their parents are.             if (!isset($view->vars['attr']['readonly']) && isset($view->parent->vars['attr']['readonly']) && false !== $view->parent->vars['attr']['readonly']) {
                $view->vars['attr']['readonly'] = true;
            }

            $helpTranslationParameters = array_merge($view->parent->vars['help_translation_parameters']$helpTranslationParameters);
        }

        $formConfig = $form->getConfig();
        


        $this->logger?->debug('Remember-me cookie detected.');

        // the `null` return value indicates that this authenticator supports lazy firewalls         return null;
    }

    public function authenticate(Request $request): Passport
    {
        if (!$rawCookie = $request->cookies->get($this->cookieName)) {
            throw new \LogicException('No remember-me cookie is found.');
        }

        $rememberMeCookie = RememberMeDetails::fromRawCookie($rawCookie);

        $userBadge = new UserBadge($rememberMeCookie->getUserIdentifier()fn () => $this->rememberMeHandler->consumeRememberMeCookie($rememberMeCookie));

        return new SelfValidatingPassport($userBadge);
    }

    public function createToken(Passport $passport, string $firewallName): TokenInterface
    {
        
\NumberFormatter::ROUND_HALFUP,
            \NumberFormatter::ROUND_UP,
            \NumberFormatter::ROUND_CEILING,
        ]);

        $resolver->setAllowedTypes('scale', 'int');

        $resolver->setAllowedTypes('html5', 'bool');

        $resolver->setNormalizer('grouping', static function DOptions $options$value) {
            if ($value && $options['html5']) {
                throw new LogicException('Cannot use the "grouping" option when the "html5" option is enabled.');
            }

            return $value;
        });
    }

    public function getBlockPrefix(): string
    {
        return 'money';
    }

    

  public function postCreate(EntityStorageInterface $storage) {
    $this->newRevision = TRUE;
  }

  /** * {@inheritdoc} */
  public function setNewRevision($value = TRUE) {
    if (!$this->getEntityType()->hasKey('revision')) {
      throw new \LogicException("Entity type {$this->getEntityTypeId()} does not support revisions.");
    }

    if ($value && !$this->newRevision) {
      // When saving a new revision, set any existing revision ID to NULL so as       // to ensure that a new revision will actually be created.       $this->set($this->getEntityType()->getKey('revision'), NULL);
    }
    elseif (!$value && $this->newRevision) {
      // If ::setNewRevision(FALSE) is called after ::setNewRevision(TRUE) we       // have to restore the loaded revision ID.       $this->set($this->getEntityType()->getKey('revision')$this->getLoadedRevisionId());
    }
if ($application instanceof RunnerInterface) {
            return $application;
        }

        if (!$application instanceof \Closure) {
            if ($runtime = $this->resolveRuntime($application::class)) {
                return $runtime->getRunner($application);
            }

            if (!\is_callable($application)) {
                throw new \LogicException(sprintf('"%s" doesn\'t know how to handle apps of type "%s".', get_debug_type($this)get_debug_type($application)));
            }

            $application = $application(...);
        }

        if ($_SERVER[$this->options['debug_var_name']] && ($r = new \ReflectionFunction($application)) && $r->getNumberOfRequiredParameters()) {
            throw new \ArgumentCountError(sprintf('Zero argument should be required by the runner callable, but at least one is in "%s" on line "%d.', $r->getFileName()$r->getStartLine()));
        }

        return new ClosureRunner($application);
    }

    

    public function getExtension(string $name): ExtensionInterface
    {
        if (isset($this->extensions[$name])) {
            return $this->extensions[$name];
        }

        if (isset($this->extensionsByNs[$name])) {
            return $this->extensionsByNs[$name];
        }

        throw new LogicException(sprintf('Container extension "%s" is not registered.', $name));
    }

    /** * Returns all registered extensions. * * @return array<string, ExtensionInterface> */
    public function getExtensions(): array
    {
        return $this->extensions;
    }

    
public function __construct()
    {
        $this->parameters = $this->getDefaultParameters();

        $this->services = $this->privates = [];

        $this->aliases = [];
    }

    public function compile(): void
    {
        throw new LogicException('You cannot compile a dumped container that was already compiled.');
    }

    public function isCompiled(): bool
    {
        return true;
    }

    public function getParameter(string $name): array|bool|string|int|float|\UnitEnum|null
    {
        if (!(isset($this->parameters[$name]) || isset($this->loadedDynamicParameters[$name]) || \array_key_exists($name$this->parameters))) {
            throw new ParameterNotFoundException($name);
        }
Home | Imprint | This part of the site doesn't use cookies.