mirror of
https://github.com/rectorphp/rector.git
synced 2025-02-24 03:35:01 +01:00
Merge pull request #3129 from rectorphp/fix-route
fix missing host at @Route annotation
This commit is contained in:
commit
4af174e1c9
@ -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={(.*?)(?<separator>(=|:))(.*)}#');
|
||||
$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,
|
||||
|
@ -43,6 +43,7 @@ final class SymfonyRoutePhpDocNodeFactory extends AbstractPhpDocNodeFactory
|
||||
$route->getMethods(),
|
||||
$route->getOptions(),
|
||||
$route->getDefaults(),
|
||||
$route->getHost(),
|
||||
$route->getRequirements(),
|
||||
$annotationContent
|
||||
);
|
||||
|
@ -0,0 +1,3 @@
|
||||
/**
|
||||
* @Route("/user", name="user_index", host="%test%", methods={"GET"})
|
||||
*/
|
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\BetterPhpDocParser\Tests\PhpDocParser\SymfonyRouteTagParser\Source;
|
||||
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
|
||||
final class RouteWithHost
|
||||
{
|
||||
/**
|
||||
* @Route("/user", name="user_index", host="%test%", methods={"GET"})
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
}
|
||||
}
|
@ -11,7 +11,7 @@ use Rector\BetterPhpDocParser\Tests\PhpDocParser\OrmTagParser\AbstractPhpDocInfo
|
||||
/**
|
||||
* @see \Rector\BetterPhpDocParser\PhpDocNode\Symfony\SymfonyRouteTagValueNode
|
||||
*/
|
||||
final class ClassMethodTest extends AbstractPhpDocInfoTest
|
||||
final class SymfonyRouteClassMethodTest extends AbstractPhpDocInfoTest
|
||||
{
|
||||
/**
|
||||
* @dataProvider provideData()
|
||||
@ -29,5 +29,7 @@ final class ClassMethodTest extends AbstractPhpDocInfoTest
|
||||
public function provideData(): Iterator
|
||||
{
|
||||
yield [__DIR__ . '/Source/SomeClassMethod.php', __DIR__ . '/Fixture/expected_some_class_method.txt'];
|
||||
|
||||
yield [__DIR__ . '/Source/RouteWithHost.php', __DIR__ . '/Fixture/expected_route_with_host.txt'];
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user