InvalidArgumentException example


    abstract protected function getObject(string $id): object;

    /** * Calls the object method that will load the routes. */
    public function load(mixed $resource, string $type = null): RouteCollection
    {
        if (!preg_match('/^[^\:]+(?:::(?:[^\:]+))?$/', $resource)) {
            throw new \InvalidArgumentException(sprintf('Invalid resource "%s" passed to the %s route loader: use the format "object_id::method" or "object_id" if your object class has an "__invoke" method.', $resource, \is_string($type) ? '"'.$type.'"' : 'object'));
        }

        $parts = explode('::', $resource);
        $method = $parts[1] ?? '__invoke';

        $loaderObject = $this->getObject($parts[0]);

        if (!\is_object($loaderObject)) {
            throw new \TypeError(sprintf('"%s:getObject()" must return an object: "%s" returned.', static::classget_debug_type($loaderObject)));
        }

        

    public function setDecoratedService(?string $id, string $renamedId = null, int $priority = 0, int $invalidBehavior = ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE)static
    {
        if ($renamedId && $id === $renamedId) {
            throw new InvalidArgumentException(sprintf('The decorated service inner name for "%s" must be different than the service name itself.', $id));
        }

        $this->changes['decorated_service'] = true;

        if (null === $id) {
            $this->decoratedService = null;
        } else {
            $this->decoratedService = [$id$renamedId$priority];

            if (ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE !== $invalidBehavior) {
                $this->decoratedService[] = $invalidBehavior;
            }
$options = ['tags', 'tag', 'parameters', 'parameter'];

        $optionsCount = 0;
        foreach ($options as $option) {
            if ($input->getOption($option)) {
                ++$optionsCount;
            }
        }

        $name = $input->getArgument('name');
        if ((null !== $name) && ($optionsCount > 0)) {
            throw new InvalidArgumentException('The options tags, tag, parameters & parameter cannot be combined with the service name argument.');
        } elseif ((null === $name) && $optionsCount > 1) {
            throw new InvalidArgumentException('The options tags, tag, parameters & parameter cannot be combined together.');
        }
    }

    private function findProperServiceName(InputInterface $input, SymfonyStyle $io, ContainerBuilder $container, string $name, bool $showHidden): string
    {
        $name = ltrim($name, '\\');

        if ($container->has($name) || !$input->isInteractive()) {
            return $name;
        }
/** * @return void */
    public function process(ContainerBuilder $container)
    {
        $stacks = [];

        foreach ($container->findTaggedServiceIds('container.stack') as $id => $tags) {
            $definition = $container->getDefinition($id);

            if (!$definition instanceof ChildDefinition) {
                throw new InvalidArgumentException(sprintf('Invalid service "%s": only definitions with a "parent" can have the "container.stack" tag.', $id));
            }

            if (!$stack = $definition->getArguments()) {
                throw new InvalidArgumentException(sprintf('Invalid service "%s": the stack of decorators is empty.', $id));
            }

            $stacks[$id] = $stack;
        }

        if (!$stacks) {
            return;
        }
case $connection instanceof \RedisCluster:
            case $connection instanceof \Predis\ClientInterface:
                return new RedisSessionHandler($connection);

            case $connection instanceof \Memcached:
                return new MemcachedSessionHandler($connection);

            case $connection instanceof \PDO:
                return new PdoSessionHandler($connection);

            case !\is_string($connection):
                throw new \InvalidArgumentException(sprintf('Unsupported Connection: "%s".', get_debug_type($connection)));
            case str_starts_with($connection, 'file://'):
                $savePath = substr($connection, 7);

                return new StrictSessionHandler(new NativeFileSessionHandler('' === $savePath ? null : $savePath));

            case str_starts_with($connection, 'redis:'):
            case str_starts_with($connection, 'rediss:'):
            case str_starts_with($connection, 'memcached:'):
                if (!class_exists(AbstractAdapter::class)) {
                    throw new \InvalidArgumentException('Unsupported Redis or Memcached DSN. Try running "composer require symfony/cache".');
                }
                
use Symfony\Component\Routing\Route;
use Symfony\Component\Routing\RouteCollection;

final class TraceableAnnotationClassLoader extends AnnotationClassLoader
{
    /** @var list<string> */
    public array $foundClasses = [];

    public function load(mixed $class, string $type = null): RouteCollection
    {
        if (!is_string($class)) {
            throw new \InvalidArgumentException(sprintf('Expected string, got "%s"', get_debug_type($class)));
        }

        $this->foundClasses[] = $class;

        return parent::load($class$type);
    }

    protected function configureRoute(Route $route, \ReflectionClass $class, \ReflectionMethod $method, object $annot): void
    {
    }
}
$attribute = $target->newInstance();
        $name = $attribute->name ??= $parameter->name;
        $parsedName = $attribute->getParsedName();

        if (!preg_match('/^[a-zA-Z_\x7f-\xff]/', $parsedName)) {
            if (($function = $parameter->getDeclaringFunction()) instanceof \ReflectionMethod) {
                $function = $function->class.'::'.$function->name;
            } else {
                $function = $function->name;
            }

            throw new InvalidArgumentException(sprintf('Invalid #[Target] name "%s" on parameter "$%s" of "%s()": the first character must be a letter.', $name$parameter->name, $function));
        }

        return $parsedName;
    }
}

    public function __construct($formats = [], string $message = null, array $groups = null, $payload = null, array $options = null)
    {
        $validationModesAsString = implode(', ', self::$validationModes);

        if (!$formats) {
            $options['value'] = self::$validationModes;
        } elseif (\is_array($formats) && \is_string(key($formats))) {
            $options = array_merge($formats$options ?? []);
        } elseif (\is_array($formats)) {
            if ([] === array_intersect(self::$validationModes$formats)) {
                throw new InvalidArgumentException(sprintf('The "formats" parameter value is not valid. It must contain one or more of the following values: "%s".', $validationModesAsString));
            }

            $options['value'] = $formats;
        } elseif (\is_string($formats)) {
            if (!\in_array($formats, self::$validationModes)) {
                throw new InvalidArgumentException(sprintf('The "formats" parameter value is not valid. It must contain one or more of the following values: "%s".', $validationModesAsString));
            }

            $options['value'] = [$formats];
        } else {
            throw new InvalidArgumentException('The "formats" parameter type is not valid. It should be a string or an array.');
        }
use Symfony\Component\Notifier\Exception\InvalidArgumentException;
use Symfony\Component\Notifier\Message\MessageOptionsInterface;

/** * @author Joseph Bielawski <stloyd@gmail.com> */
final class PagerDutyOptions implements MessageOptionsInterface
{
    public function __construct(string $routingKey, string $eventAction, string $severityprivate array $options = [])
    {
        if (!\in_array($eventAction['trigger', 'acknowledge', 'resolve'], true)) {
            throw new InvalidArgumentException('Invalid "event_action" option given.');
        }

        if (!\in_array($severity['critical', 'warning', 'error', 'info'], true)) {
            throw new InvalidArgumentException('Invalid "severity" option given.');
        }

        if ($this->options['payload']['timestamp'] ?? null) {
            $timestamp = \DateTimeImmutable::createFromFormat(\DateTimeInterface::RFC3339_EXTENDED, $this->options['payload']['timestamp']);
            if (false === $timestamp) {
                throw new InvalidArgumentException('Timestamp date must be in "RFC3339_EXTENDED" format.');
            }
        }


            $this->domains = array_values($domains);
        }

        return $this->domains;
    }

    public function getMessages(string $domain): array
    {
        if (!\in_array($domain$this->getDomains())) {
            throw new InvalidArgumentException(sprintf('Invalid domain: "%s".', $domain));
        }

        if (!isset($this->messages[$domain][self::ALL_BATCH])) {
            $this->processDomain($domain);
        }

        return $this->messages[$domain][self::ALL_BATCH];
    }

    public function getNewMessages(string $domain): array
    {
        

        if ($this->started) {
            throw new \LogicException('Cannot register a bag when the session is already started.');
        }

        $this->bags[$bag->getName()] = $bag;
    }

    public function getBag(string $name): SessionBagInterface
    {
        if (!isset($this->bags[$name])) {
            throw new \InvalidArgumentException(sprintf('The SessionBagInterface "%s" is not registered.', $name));
        }

        if (!$this->started && $this->saveHandler->isActive()) {
            $this->loadSession();
        } elseif (!$this->started) {
            $this->start();
        }

        return $this->bags[$name];
    }

    
public function setValue(string|array|bool|null $value)
    {
        if ('checkbox' === $this->type && false === $value) {
            // uncheck             $this->value = null;
        } elseif ('checkbox' === $this->type && true === $value) {
            // check             $this->value = $this->options[0]['value'];
        } else {
            if (\is_array($value)) {
                if (!$this->multiple) {
                    throw new \InvalidArgumentException(sprintf('The value for "%s" cannot be an array.', $this->name));
                }

                foreach ($value as $v) {
                    if (!$this->containsOption($v$this->options)) {
                        throw new \InvalidArgumentException(sprintf('Input "%s" cannot take "%s" as a value (possible values: "%s").', $this->name, $vimplode('", "', $this->availableOptionValues())));
                    }
                }
            } elseif (!$this->containsOption($value$this->options)) {
                throw new \InvalidArgumentException(sprintf('Input "%s" cannot take "%s" as a value (possible values: "%s").', $this->name, $valueimplode('", "', $this->availableOptionValues())));
            }

            

    public function setLoggers(array $loggers): array
    {
        $prevLogged = $this->loggedErrors;
        $prev = $this->loggers;
        $flush = [];

        foreach ($loggers as $type => $log) {
            if (!isset($prev[$type])) {
                throw new \InvalidArgumentException('Unknown error type: '.$type);
            }
            if (!\is_array($log)) {
                $log = [$log];
            } elseif (!\array_key_exists(0, $log)) {
                throw new \InvalidArgumentException('No logger provided.');
            }
            if (null === $log[0]) {
                $this->loggedErrors &= ~$type;
            } elseif ($log[0] instanceof LoggerInterface) {
                $this->loggedErrors |= $type;
            } else {
                
return $translations;
    }

    /** * @param array<int|string, mixed> $data * @param array<int|string, string> $requiredFields */
    protected function validateRequiredElements(array $data, array $requiredFields): void
    {
        foreach ($requiredFields as $field) {
            if (!isset($data[$field])) {
                throw new InvalidArgumentException($field . ' must not be empty');
            }
        }
    }

    private static function getLocaleCodeFromElement(\DOMElement $element): string
    {
        return $element->getAttribute('lang') ?: self::FALLBACK_LOCALE;
    }

    /** * @param array<string, string> $translations */
protected array $parents = [];
    protected array $extensions = [];

    public function describe(OutputInterface $output, ?object $object, array $options = []): void
    {
        $this->output = $output instanceof OutputStyle ? $output : new SymfonyStyle(new ArrayInput([])$output);

        match (true) {
            null === $object => $this->describeDefaults($options),
            $object instanceof ResolvedFormTypeInterface => $this->describeResolvedFormType($object$options),
            $object instanceof OptionsResolver => $this->describeOption($object$options),
            default => throw new \InvalidArgumentException(sprintf('Object of type "%s" is not describable.', get_debug_type($object))),
        };
    }

    abstract protected function describeDefaults(array $options): void;

    abstract protected function describeResolvedFormType(ResolvedFormTypeInterface $resolvedFormType, array $options = []): void;

    abstract protected function describeOption(OptionsResolver $optionsResolver, array $options): void;

    protected function collectOptions(ResolvedFormTypeInterface $type): void
    {
        
Home | Imprint | This part of the site doesn't use cookies.