diff --git a/Routing/Loader/Reader/RestActionReader.php b/Routing/Loader/Reader/RestActionReader.php index 6fd6d72f3..191dd367b 100644 --- a/Routing/Loader/Reader/RestActionReader.php +++ b/Routing/Loader/Reader/RestActionReader.php @@ -67,6 +67,19 @@ class RestActionReader private $availableConventionalActions = ['new', 'edit', 'remove']; private $hasMethodPrefix; + /** + * ignore several type hinted arguments. + */ + private $ignoredClasses = [ + ConstraintViolationListInterface::class, + MessageInterface::class, + ParamConverter::class, + ParamFetcherInterface::class, + Request::class, + SessionInterface::class, + UserInterface::class, + ]; + public function __construct(Reader $annotationReader, ParamReaderInterface $paramReader, InflectorInterface $inflector, bool $includeFormat, array $formats = [], bool $hasMethodPrefix = true) { $this->annotationReader = $annotationReader; @@ -157,6 +170,29 @@ public function getParents() return $this->parents; } + /** + * Set ignored classes. + * + * These classes will be ignored for route construction when + * type hinted as method argument. + * + * @param string[] $ignoredClasses + */ + public function setIgnoredClasses(array $ignoredClasses): void + { + $this->ignoredClasses = $ignoredClasses; + } + + /** + * Get ignored classes. + * + * @return string[] + */ + public function getIgnoredClasses(): array + { + return $this->ignoredClasses; + } + /** * @param string[] $resource * @@ -184,7 +220,7 @@ public function read(RestRouteCollection $collection, \ReflectionMethod $method, return; } - list($httpMethod, $resources, $isCollection, $isInflectable) = $httpMethodAndResources; + [$httpMethod, $resources, $isCollection, $isInflectable] = $httpMethodAndResources; $arguments = $this->getMethodArguments($method); // if we have only 1 resource & 1 argument passed, then it's object call, so @@ -423,17 +459,6 @@ private function getMethodArguments(\ReflectionMethod $method): array }, $this->annotationReader->getMethodAnnotations($method)); } - // ignore several type hinted arguments - $ignoreClasses = [ - ConstraintViolationListInterface::class, - MessageInterface::class, - ParamConverter::class, - ParamFetcherInterface::class, - Request::class, - SessionInterface::class, - UserInterface::class, - ]; - $arguments = []; foreach ($method->getParameters() as $argument) { if (isset($params[$argument->getName()])) { @@ -443,7 +468,7 @@ private function getMethodArguments(\ReflectionMethod $method): array $argumentClass = $argument->getClass(); if ($argumentClass) { $className = $argumentClass->getName(); - foreach ($ignoreClasses as $class) { + foreach ($this->getIgnoredClasses() as $class) { if ($className === $class || is_subclass_of($className, $class)) { continue 2; }