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 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
40 changes: 26 additions & 14 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ Symfony is the result of the work of many people who made the code better
- Johannes S (johannes)
- Javier Eguiluz (javier.eguiluz)
- Kris Wallsmith (kriswallsmith)
- Grégoire Pineau (lyrixx)
- Roland Franssen (ro0)
- Grégoire Pineau (lyrixx)
- Hugo Hamon (hhamon)
- Abdellatif Ait boudad (aitboudad)
- Romain Neutron (romain)
- Samuel ROZE (sroze)
- Romain Neutron (romain)
- Pascal Borreli (pborreli)
- Wouter De Jong (wouterj)
- Joseph Bielawski (stloyd)
Expand All @@ -40,8 +40,8 @@ Symfony is the result of the work of many people who made the code better
- Igor Wiedler (igorw)
- Eriksen Costa (eriksencosta)
- Guilhem Niot (energetick)
- Sarah Khalil (saro0h)
- Hamza Amrouche (simperfit)
- Sarah Khalil (saro0h)
- Jonathan Wage (jwage)
- Tobias Nyholm (tobias)
- Lynn van der Berg (kjarli)
Expand All @@ -68,10 +68,10 @@ Symfony is the result of the work of many people who made the code better
- Gábor Egyed (1ed)
- Bilal Amarni (bamarni)
- Titouan Galopin (tgalopin)
- Grégoire Paris (greg0ire)
- Mathieu Piot (mpiot)
- David Maicher (dmaicher)
- Florin Patan (florinpatan)
- Grégoire Paris (greg0ire)
- Gabriel Ostrolucký (gadelat)
- Valentin Udaltsov (vudaltsov)
- Vladimir Reznichenko (kalessil)
Expand All @@ -93,6 +93,7 @@ Symfony is the result of the work of many people who made the code better
- Brandon Turner
- Luis Cordova (cordoval)
- Graham Campbell (graham)
- David Buchmann (dbu)
- Daniel Holmes (dholmes)
- Toni Uebernickel (havvg)
- Bart van den Burg (burgov)
Expand All @@ -101,7 +102,6 @@ Symfony is the result of the work of many people who made the code better
- John Wards (johnwards)
- Thomas Calvet (fancyweb)
- Fran Moreno (franmomu)
- David Buchmann (dbu)
- Antoine Hérault (herzult)
- Paráda József (paradajozsef)
- Arnaud Le Blanc (arnaud-lb)
Expand Down Expand Up @@ -142,6 +142,7 @@ Symfony is the result of the work of many people who made the code better
- Alex Pott
- Vincent AUBERT (vincent)
- Juti Noppornpitak (shiroyuki)
- Teoh Han Hui (teohhanhui)
- Anthony MARTIN (xurudragon)
- Tigran Azatyan (tigranazatyan)
- Sebastian Hörl (blogsh)
Expand All @@ -151,7 +152,6 @@ Symfony is the result of the work of many people who made the code better
- Arnaud Kleinpeter (nanocom)
- Jannik Zschiesche (apfelbox)
- Guilherme Blanco (guilhermeblanco)
- Teoh Han Hui (teohhanhui)
- SpacePossum
- Pablo Godel (pgodel)
- Jérémie Augustin (jaugustin)
Expand Down Expand Up @@ -181,6 +181,7 @@ Symfony is the result of the work of many people who made the code better
- Artur Kotyrba
- Tyson Andre
- GDIBass
- Jan Schädlich (jschaedl)
- jeremyFreeAgent (Jérémy Romey) (jeremyfreeagent)
- James Halsall (jaitsu)
- Matthieu Napoli (mnapoli)
Expand All @@ -192,13 +193,15 @@ Symfony is the result of the work of many people who made the code better
- Daniel Espendiller
- Possum
- Dorian Villet (gnutix)
- George Mponos (gmponos)
- Sergey Linnik (linniksa)
- Richard Miller (mr_r_miller)
- Albert Casademont (acasademont)
- Mario A. Alvarez Garcia (nomack84)
- Dennis Benkert (denderello)
- DQNEO
- Samuel NELA (snela)
- Alexander Schranz (alexander-schranz)
- Gregor Harlan (gharlan)
- Gary PEGEOT (gary-p)
- Ruben Gonzalez (rubenrua)
Expand All @@ -213,7 +216,6 @@ Symfony is the result of the work of many people who made the code better
- bronze1man
- sun (sun)
- Larry Garfield (crell)
- George Mponos (gmponos)
- Michaël Perrin (michael.perrin)
- Nikolay Labinskiy (e-moe)
- Martin Schuhfuß (usefulthink)
Expand All @@ -225,7 +227,6 @@ Symfony is the result of the work of many people who made the code better
- Dominique Bongiraud
- Jeremy Livingston (jeremylivingston)
- Vincent Touzet (vincenttouzet)
- Jan Schädlich (jschaedl)
- Michael Lee (zerustech)
- Matthieu Auger (matthieuauger)
- Leszek Prabucki (l3l0)
Expand All @@ -237,7 +238,6 @@ Symfony is the result of the work of many people who made the code better
- Andreas Schempp (aschempp)
- Justin Hileman (bobthecow)
- Blanchon Vincent (blanchonvincent)
- Alexander Schranz (alexander-schranz)
- Michele Orselli (orso)
- Sven Paulus (subsven)
- Maxime Veber (nek-)
Expand Down Expand Up @@ -303,12 +303,14 @@ Symfony is the result of the work of many people who made the code better
- Bob den Otter (bopp)
- Thomas Schulz (king2500)
- Frank de Jonge (frenkynet)
- Andre Rømcke (andrerom)
- Nikita Konstantinov
- Wodor Wodorski
- Thomas Lallement (raziel057)
- mcfedr (mcfedr)
- Colin O'Dell (colinodell)
- Giorgio Premi
- renanbr
- Alex Rock (pierstoval)
- Ben Davies (bendavies)
- Beau Simensen (simensen)
Expand Down Expand Up @@ -371,7 +373,6 @@ Symfony is the result of the work of many people who made the code better
- Ricard Clau (ricardclau)
- Mark Challoner (markchalloner)
- Gennady Telegin (gtelegin)
- renanbr
- Erin Millard
- Artur Melo (restless)
- Matthew Lewinski (lewinski)
Expand All @@ -380,7 +381,6 @@ Symfony is the result of the work of many people who made the code better
- Nicolas LEFEVRE (nicoweb)
- alquerci
- Mateusz Sip (mateusz_sip)
- Andre Rømcke (andrerom)
- Francesco Levorato
- Dmitrii Poddubnyi (karser)
- Vitaliy Zakharov (zakharovvi)
Expand All @@ -391,6 +391,7 @@ Symfony is the result of the work of many people who made the code better
- Tomasz Kowalczyk (thunderer)
- Artur Eshenbrener
- Andreas Braun
- Arjen van der Meijden
- Damien Alexandre (damienalexandre)
- Thomas Perez (scullwm)
- Felix Labrecque
Expand All @@ -411,6 +412,7 @@ Symfony is the result of the work of many people who made the code better
- Grzegorz (Greg) Zdanowski (kiler129)
- Iker Ibarguren (ikerib)
- Kirill chEbba Chebunin (chebba)
- Stadly
- Greg Thornton (xdissent)
- Quynh Xuan Nguyen (xuanquynh)
- Martin Hujer (martinhujer)
Expand Down Expand Up @@ -558,10 +560,10 @@ Symfony is the result of the work of many people who made the code better
- Jakub Škvára (jskvara)
- Andrew Udvare (audvare)
- alexpods
- Arjen van der Meijden
- Adam Szaraniec (mimol)
- Dariusz Ruminski
- Erik Trapman (eriktrapman)
- Rokas Mikalkėnas (rokasm)
- De Cock Xavier (xdecock)
- Almog Baku (almogbaku)
- Scott Arciszewski
Expand Down Expand Up @@ -806,7 +808,6 @@ Symfony is the result of the work of many people who made the code better
- John Bohn (jbohn)
- Marc Morera (mmoreram)
- Saif Eddin Gmati (azjezz)
- Stadly
- Andrew Hilobok (hilobok)
- Noah Heck (myesain)
- Christian Soronellas (theunic)
Expand Down Expand Up @@ -960,14 +961,14 @@ Symfony is the result of the work of many people who made the code better
- Benoît Merlet (trompette)
- Koen Kuipers
- datibbaw
- Rokas Mikalkėnas (rokasm)
- Erik Saunier (snickers)
- Rootie
- Kyle
- Daniel Alejandro Castro Arellano (lexcast)
- sensio
- Chris Tanaskoski
- Thomas Jarrand
- Antoine Bluchet (soyuka)
- Sebastien Morel (plopix)
- Patrick Kaufmann
- Anton Dyshkant
Expand Down Expand Up @@ -1009,6 +1010,7 @@ Symfony is the result of the work of many people who made the code better
- Joost van Driel
- Icode4Food (icode4food)
- Radosław Benkel
- EStyles (insidestyles)
- kevin.nadin
- jean pasqualini (darkilliant)
- Ross Motley (rossmotley)
Expand All @@ -1035,6 +1037,7 @@ Symfony is the result of the work of many people who made the code better
- Ashura
- Hryhorii Hrebiniuk
- johnstevenson
- Antonio Pauletich (x-coder264)
- hamza
- dantleech
- Bastien DURAND (deamon)
Expand All @@ -1054,6 +1057,7 @@ Symfony is the result of the work of many people who made the code better
- chispita
- Wojciech Sznapka
- Gavin Staniforth
- Ksaveras Šakys (xawiers)
- Ariel J. Birnbaum
- Danijel Obradović
- Pablo Borowicz
Expand All @@ -1078,6 +1082,7 @@ Symfony is the result of the work of many people who made the code better
- Mert Simsek (mrtsmsk0)
- Lin Clark
- Jeremy David (jeremy.david)
- Jordi Rejas
- Troy McCabe
- Ville Mattila
- ilyes kooli
Expand Down Expand Up @@ -1204,6 +1209,7 @@ Symfony is the result of the work of many people who made the code better
- antograssiot
- Ilya Vertakov
- Brooks Boyd
- johnillo
- Roger Webb
- Dmitriy Simushev
- Pawel Smolinski
Expand Down Expand Up @@ -1272,6 +1278,7 @@ Symfony is the result of the work of many people who made the code better
- Lars Ambrosius Wallenborn (larsborn)
- Oriol Mangas Abellan (oriolman)
- Sebastian Göttschkes (sgoettschkes)
- Toni Peric (tperic)
- Tatsuya Tsuruoka
- Ross Tuck
- Andreas Erhard
Expand Down Expand Up @@ -1407,6 +1414,7 @@ Symfony is the result of the work of many people who made the code better
- Jon Gotlin (jongotlin)
- Michael Dowling (mtdowling)
- Karlos Presumido (oneko)
- Tony Vermeiren (tony)
- Thomas Counsell
- BilgeXA
- r1pp3rj4ck
Expand Down Expand Up @@ -1519,6 +1527,7 @@ Symfony is the result of the work of many people who made the code better
- Francisco Facioni (fran6co)
- Iwan van Staveren (istaveren)
- Povilas S. (povilas)
- Laurent Negre (raulnet)
- Evrard Boulou
- pborreli
- Boris Betzholz
Expand Down Expand Up @@ -1716,6 +1725,7 @@ Symfony is the result of the work of many people who made the code better
- Dmitriy Fedorenko
- vlakoff
- bertillon
- thib92
- Rudolf Ratusiński
- Bertalan Attila
- AmsTaFF (amstaff)
Expand Down Expand Up @@ -1882,6 +1892,7 @@ Symfony is the result of the work of many people who made the code better
- Yorkie Chadwick (yorkie76)
- GuillaumeVerdon
- Philipp Keck
- Angel Fernando Quiroz Campos
- Ondrej Mirtes
- akimsko
- Youpie
Expand Down Expand Up @@ -2129,6 +2140,7 @@ Symfony is the result of the work of many people who made the code better
- samuel laulhau (lalop)
- Laurent Bachelier (laurentb)
- Luís Cobucci (lcobucci)
- Mehdi Achour (machour)
- Marcos Gómez Vilches (markitosgv)
- Matthieu Mota (matthieumota)
- Matthieu Moquet (mattketmo)
Expand Down
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
Contributor

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