8000 [FrameworkBundle]: use __invoke function if no method is defined in r… by rjwebdev · Pull Request #31367 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[FrameworkBundle]: use __invoke function if no method is defined in r… #31367

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

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
[FrameworkBundle]: use __invoke function if no method is defined in r…
…outing configuration
  • Loading branch information
rjwebdev authored and Ruben Jacobs committed May 6, 2019
commit 881a02f583bb6cec0194fb812441d080b6398445
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,14 @@ protected function createController($controller)
@trigger_error(sprintf('Referencing controllers with %s is deprecated since Symfony 4.1. Use %s instead.', $deprecatedNotation, $controller), E_USER_DEPRECATED);
}

return parent::createController($controller);
if (\is_object($resolvedController) && method_exists($resolvedController, '__invoke')) {
$resolvedController = [
$this->configureController($resolvedController),
'__invoke',
];
}

return $resolvedController;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,24 @@

class ControllerResolverTest extends ContainerControllerResolverTest
{
public function testGetControllerWithServiceWithoutMethod()
{
class_exists(AbstractControllerTest::class);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the reason for the class_exists() call here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No specific reason. Think it's better to remove it but since I have to start from master branch, I should rework the entire new code


$dummyController = new DummyController();
$container = new Container();
$container->set('app.index_controller', $dummyController);

$resolver = $this->createControllerResolver(null, $container);
$request = Request::create('/');
$request->attributes->set('_controller', 'app.index_controller');

$controller = $resolver->getController($request);

$this->assertSame($container, $controller[0]->getContainer());
$this->assertSame('__invoke', $controller[1]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rjwebdev I would follow the same logic as in testGetControllerOnContainerAwareInvokable:

$this->assertInstanceOf('Symfony\Bundle\FrameworkBundle\Tests\Controller\DummyController', $controller);
$this->assertInstanceOf('Symfony\Component\DependencyInjection\ContainerInterface', $controller->getContainer());

}

public function testGetControllerOnContainerAware()
{
$resolver = $this->createControllerResolver();
Expand Down Expand Up @@ -230,6 +248,10 @@ public function getContainer()
return $this->container;
}

public function __invoke()
{
}

public function fooAction()
{
}
Expand Down
0