Skip to content

[FrameworkBundle][Routing] Add link to source to router:match #36144

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ CHANGELOG
5.1.0
-----

* Added link to source on controller on `router:match`/`debug:router` (when `framework.ide` is configured)
* Added `Routing\Loader` and `Routing\Loader\Configurator` namespaces to ease defining routes with default controllers
* Added the `framework.router.context` configuration node to configure the `RequestContext`
* Made `MicroKernelTrait::configureContainer()` compatible with `ContainerConfigurator`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ protected function describeRouteCollection(RouteCollection $routes, array $optio

protected function describeRoute(Route $route, array $options = [])
{
$defaults = $route->getDefaults();
if (isset($defaults['_controller'])) {
$defaults['_controller'] = $this->formatControllerLink($defaults['_controller'], $this->formatCallable($defaults['_controller']));
}

$tableHeaders = ['Property', 'Value'];
$tableRows = [
['Route Name', isset($options['name']) ? $options['name'] : ''],
Expand All @@ -93,7 +98,7 @@ protected function describeRoute(Route $route, array $options = [])
['Method', ($route->getMethods() ? implode('|', $route->getMethods()) : 'ANY')],
['Requirements', ($route->getRequirements() ? $this->formatRouterConfig($route->getRequirements()) : 'NO CUSTOM')],
['Class', \get_class($route)],
['Defaults', $this->formatRouterConfig($route->getDefaults())],
['Defaults', $this->formatRouterConfig($defaults)],
['Options', $this->formatRouterConfig($route->getOptions())],
];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,13 @@
namespace Symfony\Bundle\FrameworkBundle\Tests\Console\Descriptor;

use Symfony\Bundle\FrameworkBundle\Console\Descriptor\TextDescriptor;
use Symfony\Component\HttpKernel\Debug\FileLinkFormatter;
use Symfony\Component\Routing\Route;

class TextDescriptorTest extends AbstractDescriptorTest
{
private $fileLinkFormatter = null;

protected function setUp(): void
{
putenv('COLUMNS=121');
Expand All @@ -27,11 +31,41 @@ protected function tearDown(): void

protected function getDescriptor()
{
return new TextDescriptor();
return new TextDescriptor($this->fileLinkFormatter);
}

protected function getFormat()
{
return 'txt';
}

public function getDescribeRouteWithControllerLinkTestData()
{
$getDescribeData = $this->getDescribeRouteTestData();

foreach ($getDescribeData as $key => &$data) {
$routeStub = $data[0];
$routeStub->setDefault('_controller', sprintf('%s::%s', MyController::class, '__invoke'));
$file = $data[2];
$file = preg_replace('#(\..*?)$#', '_link$1', $file);
$data = file_get_contents(__DIR__.'/../../Fixtures/Descriptor/'.$file);
$data = [$routeStub, $data, $file];
}

return $getDescribeData;
}

/** @dataProvider getDescribeRouteWithControllerLinkTestData */
public function testDescribeRouteWithControllerLink(Route $route, $expectedDescription)
{
$this->fileLinkFormatter = new FileLinkFormatter('myeditor://open?file=%f&line=%l');
parent::testDescribeRoute($route, str_replace('[:file:]', __FILE__, $expectedDescription));
}
}

class MyController
{
public function __invoke()
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
+--------------+-----------------------------------------------------------------------------------------------+
| Property | Value |
+--------------+-----------------------------------------------------------------------------------------------+
| Route Name | |
| Path | /hello/{name} |
| Path Regex | #PATH_REGEX# |
| Host | localhost |
| Host Regex | #HOST_REGEX# |
| Scheme | http|https |
| Method | GET|HEAD |
| Requirements | name: [a-z]+ |
| Class | Symfony\Bundle\FrameworkBundle\Tests\Console\Descriptor\RouteStub |
| Defaults | _controller: ]8;;myeditor://open?file=[:file:]&line=68\Symfony\Bundle\FrameworkBundle\Tests\Console\Descriptor\MyController::__invoke()]8;;\ |
| | name: Joseph |
| Options | compiler_class: Symfony\Component\Routing\RouteCompiler |
| | opt1: val1 |
| | opt2: val2 |
+--------------+-----------------------------------------------------------------------------------------------+
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
+--------------+-----------------------------------------------------------------------------------------------+
| Property | Value |
+--------------+-----------------------------------------------------------------------------------------------+
| Route Name | |
| Path | /name/add |
| Path Regex | #PATH_REGEX# |
| Host | localhost |
| Host Regex | #HOST_REGEX# |
| Scheme | http|https |
| Method | PUT|POST |
| Requirements | NO CUSTOM |
| Class | Symfony\Bundle\FrameworkBundle\Tests\Console\Descriptor\RouteStub |
| Defaults | _controller: ]8;;myeditor://open?file=[:file:]&line=68\Symfony\Bundle\FrameworkBundle\Tests\Console\Descriptor\MyController::__invoke()]8;;\ |
| Options | compiler_class: Symfony\Component\Routing\RouteCompiler |
| | opt1: val1 |
| | opt2: val2 |
| Condition | context.getMethod() in ['GET', 'HEAD', 'POST'] |
+--------------+-----------------------------------------------------------------------------------------------+