8000 [FrameworkBundle][Routing] Add link to source to router:match · symfony/symfony@dad19bb · GitHub
[go: up one dir, main page]

Skip to content

Commit dad19bb

Browse files
committed
[FrameworkBundle][Routing] Add link to source to router:match
1 parent cda20aa commit dad19bb

File tree

5 files changed

+78
-2
lines changed

5 files changed

+78
-2
lines changed

src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ CHANGELOG
44
5.1.0
55
-----
66

7+
* Added link to source on controller on `router:match`/`debug:router` (when `framework.ide` is configured)
78
* Added `Routing\Loader` and `Routing\Loader\Configurator` namespaces to ease defining routes with default controllers
89
* Added the `framework.router.context` configuration node to configure the `RequestContext`
910
* Made `MicroKernelTrait::configureContainer()` compatible with `ContainerConfigurator`

src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/TextDescriptor.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@ protected function describeRouteCollection(RouteCollection $routes, array $optio
8282

8383
protected function describeRoute(Route $route, array $options = [])
8484
{
85+
$defaults = $route->getDefaults();
86+
if (!empty($defaults['_controller'])) {
87+
$defaults['_controller'] = $this->formatControllerLink($defaults['_controller'], $defaults['_controller']);
88+
}
89+
8590
$tableHeaders = ['Property', 'Value'];
8691
$tableRows = [
8792
['Route Name', isset($options['name']) ? $options['name'] : ''],
@@ -93,7 +98,7 @@ protected function describeRoute(Route $route, array $options = [])
9398
['Method', ($route->getMethods() ? implode('|', $route->getMethods()) : 'ANY')],
9499
['Requirements', ($route->getRequirements() ? $this->formatRouterConfig($route->getRequirements()) : 'NO CUSTOM')],
95100
['Class', \get_class($route)],
96-
['Defaults', $this->formatRouterConfig($route->getDefaults())],
101+
['Defaults', $this->formatRouterConfig($defaults)],
97102
['Options', $this->formatRouterConfig($route->getOptions())],
98103
];
99104

src/Symfony/Bundle/FrameworkBundle/Tests/Console/Descriptor/TextDescriptorTest.php

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,13 @@
1212
namespace Symfony\Bundle\FrameworkBundle\Tests\Console\Descriptor;
1313

1414
use Symfony\Bundle\FrameworkBundle\Console\Descriptor\TextDescriptor;
15+
use Symfony\Component\HttpKernel\Debug\FileLinkFormatter;
16+
use Symfony\Component\Routing\Route;
1517

1618
class TextDescriptorTest extends AbstractDescriptorTest
1719
{
20+
private $fileLinkFormatter = null;
21+
1822
protected function setUp(): void
1923
{
2024
putenv('COLUMNS=121');
@@ -27,11 +31,41 @@ protected function tearDown(): void
2731

2832
protected function getDescriptor()
2933
{
30-
return new TextDescriptor();
34+
return new TextDescriptor($this->fileLinkFormatter);
3135
}
3236

3337
protected function getFormat()
3438
{
3539
return 'txt';
3640
}
41+
42+
public function getDescribeRouteWithControllerLinkTestData()
43+
{
44+
$getDescribeData = $this->getDescribeRouteTestData();
45+
46+
foreach ($getDescribeData as $key => &$data) {
47+
$routeStub = $data[0];
48+
$routeStub->setDefault('_controller', sprintf('%s::%s', MyController::class, '__invoke'));
49+
$file = $data[2];
50+
$file = preg_replace('#(\..*?)$#', '_link$1', $file);
51+
$data = file_get_contents(__DIR__.'/../../Fixtures/Descriptor/'.$file);
52+
$data = [$routeStub, $data, $file];
53+
}
54+
55+
return $getDescribeData;
56+
}
57+
58+
/** @dataProvider getDescribeRouteWithControllerLinkTestData */
59+
public function testDescribeRouteWithControllerLink(Route $route, $expectedDescription)
60+
{
61+
$this->fileLinkFormatter = new FileLinkFormatter('myeditor://open?file=%f&line=%l');
62+
parent::testDescribeRoute($route, str_replace('[:file:]', __FILE__, $expectedDescription));
63+
}
64+
}
65+
66+
class MyContr A3D4 oller
67+
{
68+
public function __invoke()
69+
{
70+
}
3771
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
+--------------+---------------------------------------------------------------------------------------------+
2+
| Property | Value |
3+
+--------------+---------------------------------------------------------------------------------------------+
4+
| Route Name | |
5+
| Path | /hello/{name} |
6+
| Path Regex | #PATH_REGEX# |
7+
| Host | localhost |
8+
| Host Regex | #HOST_REGEX# |
9+
| Scheme | http|https |
10+
| Method | GET|HEAD |
11+
| Requirements | name: [a-z]+ |
12+
| Class | Symfony\Bundle\FrameworkBundle\Tests\Console\Descriptor\RouteStub |
13+
| Defaults | _controller: ]8;;myeditor://open?file=[:file:]&line=68\Symfony\Bundle\FrameworkBundle\Tests\Console\Descriptor\MyController::__invoke]8;;\ |
14+
| | name: Joseph |
15+
| Options | compiler_class: Symfony\Component\Routing\RouteCompiler |
16+
| | opt1: val1 |
17+
| | opt2: val2 |
18+
+--------------+---------------------------------------------------------------------------------------------+
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
+--------------+---------------------------------------------------------------------------------------------+
2+
| Property | Value |
3+
+--------------+---------------------------------------------------------------------------------------------+
4+
| Route Name | |
5+
| Path | /name/add |
6+
| Path Regex | #PATH_REGEX# |
7+
| Host | localhost |
8+
| Host Regex | #HOST_REGEX# |
9+
| Scheme | http|https |
10+
| Method | PUT|POST |
11+
| Requirements | NO CUSTOM |
12+
| Class | Symfony\Bundle\FrameworkBundle\Tests\Console\Descriptor\RouteStub |
13+
| Defaults | _controller: ]8;;myeditor://open?file=[:file:]&line=68\Symfony\Bundle\FrameworkBundle\Tests\Console\Descriptor\MyController::__invoke]8;;\ |
14+
| Options | compiler_class: Symfony\Component\Routing\RouteCompiler |
15+
| | opt1: val1 |
16+
| | opt2: val2 |
17+
| Condition | context.getMethod() in ['GET', 'HEAD', 'POST'] |
18+
+--------------+---------------------------------------------------------------------------------------------+

0 commit comments

Comments
 (0)
0