{"record":{"id":"5a4e800f88ddcaf5","repo":"symfony/routing","slug":"you-should-either-pass-a-s-instance-or-provide-the","errorCode":null,"errorMessage":"You should either pass a \"%s\" instance or provide the $parameters argument of the \"%s\" method.","messagePattern":"You should either pass a \"(.+?)\" instance or provide the \\$parameters argument of the \"(.+?)\" method\\.","errorType":"exception","errorClass":"LogicException","httpStatus":null,"severity":"error","filePath":"DependencyInjection/Router.php","lineNumber":64,"sourceCode":"        private ContainerInterface $container,\n        mixed $resource,\n        array $options = [],\n        ?RequestContext $context = null,\n        ?ContainerInterface $parameters = null,\n        ?LoggerInterface $logger = null,\n        ?string $defaultLocale = null,\n    ) {\n        $this->resource = $resource;\n        $this->context = $context ?? new RequestContext();\n        $this->logger = $logger;\n        $this->setOptions($options);\n\n        if ($parameters) {\n            $this->paramFetcher = $parameters->get(...);\n        } elseif ($container instanceof SymfonyContainerInterface) {\n            $this->paramFetcher = $container->getParameter(...);\n        } else {\n            throw new \\LogicException(\\sprintf('You should either pass a \"%s\" instance or provide the $parameters argument of the \"%s\" method.', SymfonyContainerInterface::class, __METHOD__));\n        }\n\n        $this->defaultLocale = $defaultLocale;\n    }\n\n    public function getRouteCollection(): RouteCollection\n    {\n        if (!isset($this->collection)) {\n            $this->collection = $this->container->get('routing.loader')->load($this->resource, $this->options['resource_type']);\n            $this->resolveParameters($this->collection);\n            $this->collection->addResource(new ContainerParametersResource($this->collectedParameters));\n\n            try {\n                $containerFile = ($this->paramFetcher)('kernel.build_dir').'/'.($this->paramFetcher)('kernel.container_class').'.php';\n                if (file_exists($containerFile)) {\n                    $this->collection->addResource(new FileResource($containerFile));\n                } else {\n                    $this->collection->addResource(new FileExistenceResource($containerFile));","sourceCodeStart":46,"sourceCodeEnd":82,"githubUrl":"https://github.com/symfony/routing/blob/83fa223250b50f4f018c011e101c330e65ac63cc/DependencyInjection/Router.php#L46-L82","documentation":"DependencyInjection\\Router needs a way to fetch route parameters: either a Psr\\Container\\ContainerInterface (whose $parameters is a ContainerParamFetcher-like object exposing get()) or a Symfony ContainerInterface to read parameters via getParameter(). If the $container passed is neither, a LogicException is thrown instructing to pass a PSR-11 container or provide $parameters.","triggerScenarios":"new Router($containerThatIsNotPsr11NorSymfonyContainer, $loader, $routes, ...) where $parameters is null and the container doesn't implement Symfony's ContainerInterface (e.g. a custom PSR-11 wrapper without the Psr\\Container\\ContainerInterface type, wrong container passed, or null container).","commonSituations":"Constructing the DI Router manually in tests or standalone apps with a homemade container; passing a PSR-11-only container that isn't Symfony's (note it must implement Psr\\Container\\ContainerInterface to satisfy $parameters->get), version differences after the $parameters argument was added in Symfony 6.1.","solutions":["Pass a Psr\\Container\\ContainerInterface instance (or Symfony Container) as the first constructor argument","Provide the $parameters argument explicitly (a callable/fetcher with get()) instead of relying on the container","Use the framework's dependency-injected router service rather than instantiating it manually"],"exampleFix":"// before\n$router = new Router($somePlainObject, $loader, $routes);\n// after\n$router = new Router($container, $loader, $routes, [], null, null, $parameters: $container);","handlingStrategy":"type-guard","validationCode":"if (!$container instanceof \\Psr\\Container\\ContainerInterface && !$container instanceof \\Symfony\\Component\\DependencyInjection\\ContainerInterface && null === $parameters) {\n    throw new \\LogicException('Provide a PSR-11/Symfony container or a $parameters argument');\n}","typeGuard":"function isRouterContainer(mixed $c): bool {\n    return $c instanceof \\Psr\\Container\\ContainerInterface\n        || $c instanceof \\Symfony\\Component\\DependencyInjection\\ContainerInterface;\n}","tryCatchPattern":"try {\n    $router = new \\Symfony\\Component\\Routing\\DependencyInjection\\Router($container, $loader, $routes);\n} catch (\\LogicException $e) {\n    // retry passing an explicit $parameters fetcher\n}","preventionTips":["Instantiate the DI Router only with a real PSR-11 or Symfony container","Use the container-built router service instead of manual construction","Match the constructor signature of your installed Symfony version (>=6.1 supports $parameters)"],"tags":["php","routing","dependency-injection","constructor"],"backgroundTag":"invalid-constructor-argument","analyzedSha":"83fa223250b50f4f018c011e101c330e65ac63cc","analyzedAt":"2026-09-14T03:19:46.280Z","contentChangedAt":"2026-09-14T03:19:46.280Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}