diff --git a/packages/better-php-doc-parser/src/PhpDocNode/Symfony/SymfonyRouteTagValueNode.php b/packages/better-php-doc-parser/src/PhpDocNode/Symfony/SymfonyRouteTagValueNode.php index eedbed3a55a..ba8f69a0067 100644 --- a/packages/better-php-doc-parser/src/PhpDocNode/Symfony/SymfonyRouteTagValueNode.php +++ b/packages/better-php-doc-parser/src/PhpDocNode/Symfony/SymfonyRouteTagValueNode.php @@ -9,6 +9,9 @@ use Rector\BetterPhpDocParser\Contract\PhpDocNode\ShortNameAwareTagInterface; use Rector\BetterPhpDocParser\PhpDocNode\AbstractTagValueNode; use Symfony\Component\Routing\Annotation\Route; +/** + * @see \Rector\BetterPhpDocParser\Tests\PhpDocParser\SymfonyRouteTagParser\SymfonyRouteClassMethodTest + */ final class SymfonyRouteTagValueNode extends AbstractTagValueNode implements ShortNameAwareTagInterface { /** @@ -26,6 +29,11 @@ final class SymfonyRouteTagValueNode extends AbstractTagValueNode implements Sho */ private $path; + /** + * @var string|null + */ + private $host; + /** * @var bool */ @@ -75,6 +83,7 @@ final class SymfonyRouteTagValueNode extends AbstractTagValueNode implements Sho array $methods = [], array $options = [], array $defaults = [], + ?string $host = null, array $requirements = [], ?string $originalContent = null ) { @@ -103,6 +112,7 @@ final class SymfonyRouteTagValueNode extends AbstractTagValueNode implements Sho $matches = Strings::match($originalContent, '#requirements={(.*?)(?(=|:))(.*)}#'); $this->requirementsKeyValueSeparator = $matches['separator'] ?? '='; } + $this->host = $host; } public function __toString(): string @@ -127,6 +137,10 @@ final class SymfonyRouteTagValueNode extends AbstractTagValueNode implements Sho $contentItems['defaults'] = $this->printArrayItem($this->defaults, 'defaults'); } + if ($this->host !== null) { + $contentItems['host'] = sprintf('host="%s"', $this->host); + } + if ($this->requirements !== []) { $contentItems['requirements'] = $this->printArrayItemWithSeparator( $this->requirements, diff --git a/packages/better-php-doc-parser/src/PhpDocNodeFactory/Symfony/SymfonyRoutePhpDocNodeFactory.php b/packages/better-php-doc-parser/src/PhpDocNodeFactory/Symfony/SymfonyRoutePhpDocNodeFactory.php index a38ca1627dd..d0056c48520 100644 --- a/packages/better-php-doc-parser/src/PhpDocNodeFactory/Symfony/SymfonyRoutePhpDocNodeFactory.php +++ b/packages/better-php-doc-parser/src/PhpDocNodeFactory/Symfony/SymfonyRoutePhpDocNodeFactory.php @@ -43,6 +43,7 @@ final class SymfonyRoutePhpDocNodeFactory extends AbstractPhpDocNodeFactory $route->getMethods(), $route->getOptions(), $route->getDefaults(), + $route->getHost(), $route->getRequirements(), $annotationContent ); diff --git a/packages/better-php-doc-parser/tests/PhpDocParser/SymfonyRouteTagParser/Fixture/expected_route_with_host.txt b/packages/better-php-doc-parser/tests/PhpDocParser/SymfonyRouteTagParser/Fixture/expected_route_with_host.txt new file mode 100644 index 00000000000..af3b24dd38b --- /dev/null +++ b/packages/better-php-doc-parser/tests/PhpDocParser/SymfonyRouteTagParser/Fixture/expected_route_with_host.txt @@ -0,0 +1,3 @@ +/** + * @Route("/user", name="user_index", host="%test%", methods={"GET"}) + */ \ No newline at end of file diff --git a/packages/better-php-doc-parser/tests/PhpDocParser/SymfonyRouteTagParser/Source/RouteWithHost.php b/packages/better-php-doc-parser/tests/PhpDocParser/SymfonyRouteTagParser/Source/RouteWithHost.php new file mode 100644 index 00000000000..36b48d1bc69 --- /dev/null +++ b/packages/better-php-doc-parser/tests/PhpDocParser/SymfonyRouteTagParser/Source/RouteWithHost.php @@ -0,0 +1,17 @@ +