-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[FrameworkBundle][Routing] Add a new tag to be able to use a private service as a service route loader #30926
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,9 +40,14 @@ | |
<argument type="service" id="file_locator" /> | ||
</service> | ||
|
||
<service id="routing.loader.service.container" class="Symfony\Component\Routing\Loader\DependencyInjection\ServiceRouterLoaderContainer"> | ||
<argument type="service" id="service_container" /> | ||
<argument type="tagged_locator" tag="routing.router_loader" index-by="service_id" /> | ||
fancyweb marked this conversation as resolved.
Show resolved
Hide resolved
|
||
</service> | ||
|
||
<service id="routing.loader.service" class="Symfony\Component\Routing\Loader\DependencyInjection\ServiceRouterLoader"> | ||
<tag name="routing.loader" /> | ||
<argument type="service" id="service_container" /> | ||
<argument type="service" id="routing.loader.service.container" /> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In 5.0, replace this argument with the above tagged locator. |
||
</service> | ||
|
||
<service id="routing.loader" class="Symfony\Bundle\FrameworkBundle\Routing\DelegatingLoader" public="true"> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\Routing\Loader\DependencyInjection; | ||
|
||
use Psr\Container\ContainerInterface; | ||
|
||
/** | ||
* @internal | ||
fancyweb marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* | ||
* @deprecated since Symfony 4.3, to be removed in 5.0 | ||
fancyweb marked this conversation as resolved.
Show resolved
Hide resolved
|
||
*/ | ||
class ServiceRouterLoaderContainer implements ContainerInterface | ||
fancyweb marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suggested |
||
{ | ||
private $container; | ||
private $serviceLocator; | ||
|
||
public function __construct(ContainerInterface $container, ContainerInterface $serviceLocator) | ||
{ | ||
$this->container = $container; | ||
$this->serviceLocator = $serviceLocator; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function get($id) | ||
{ | ||
if ($this->serviceLocator->has($id)) { | ||
return $this->serviceLocator->get($id); | ||
} | ||
|
||
@trigger_error(sprintf('Registering the routing loader "%s" without tagging it with the "routing.router_loader" tag is deprecated since Symfony 4.3 and will be required in Symfony 5.0.', $id), E_USER_DEPRECATED); | ||
|
||
return $this->container->get($id); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function has($id) | ||
{ | ||
return $this->serviceLocator->has($id) || $this->container->has($id); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\Routing\Loader\DependencyInjection; | ||
|
||
/** | ||
* Marker interface for router loader services. | ||
*/ | ||
interface ServiceRouterLoaderInterface | ||
fancyweb marked this conversation as resolved.
Show resolved
Hide resolved
fancyweb marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\Routing\Tests\Loader; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Psr\Container\ContainerInterface; | ||
use Symfony\Component\DependencyInjection\Container; | ||
use Symfony\Component\Routing\Loader\DependencyInjection\ServiceRouterLoaderContainer; | ||
|
||
class ServiceRouterLoaderContainerTest extends TestCase | ||
{ | ||
/** | ||
* @var ContainerInterface | ||
*/ | ||
private $container; | ||
|
||
/** | ||
* @var ContainerInterface | ||
*/ | ||
private $serviceLocator; | ||
|
||
/** | ||
* @var ServiceRouterLoaderContainer | ||
*/ | ||
private $serviceRouterLoaderContainer; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function setUp() | ||
{ | ||
$this->container = new Container(); | ||
$this->container->set('foo', new \stdClass()); | ||
|
||
$this->serviceLocator = new Container(); | ||
$this->serviceLocator->set('bar', new \stdClass()); | ||
|
||
$this->serviceRouterLoaderContainer = new ServiceRouterLoaderContainer($this->container, $this->serviceLocator); | ||
} | ||
|
||
/** | ||
* @group legacy | ||
* @expectedDeprecation Registering the routing loader "foo" without tagging it with the "routing.router_loader" tag is deprecated since Symfony 4.3 and will be required in Symfony 5.0. | ||
*/ | ||
public function testGet() | ||
{ | ||
$this->assertSame($this->container->get('foo'), $this->serviceRouterLoaderContainer->get('foo')); | ||
$this->assertSame($this->serviceLocator->get('bar'), $this->serviceRouterLoaderContainer->get('bar')); | ||
} | ||
|
||
public function testHas() | ||
{ | ||
$this->assertTrue($this->serviceRouterLoaderContainer->has('foo')); | ||
$this->assertTrue($this->serviceRouterLoaderContainer->has('bar')); | ||
$this->assertFalse($this->serviceRouterLoaderContainer->has('ccc')); | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.