8000 [FrameworkBundle] Support autowiring for RouterInterface · symfony/symfony@4d38d4b · GitHub
[go: up one dir, main page]

Skip to content

Commit 4d38d4b

Browse files
committed
[FrameworkBundle] Support autowiring for RouterInterface
1 parent 1be2a97 commit 4d38d4b

File tree

4 files changed

+31
-2
lines changed

4 files changed

+31
-2
lines changed

src/Symfony/Bundle/FrameworkBundle/Resources/config/routing.xml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,12 @@
7474
</call>
7575
</service>
7676

77-
<service id="router" alias="router.default" />
77+
<service id="router" alias="router.default">
78+
<autowiring-type>Symfony\Component\Routing\Generator\UrlGeneratorInterface</autowiring-type>
79+
<autowiring-type>Symfony\Component\Routing\Matcher\UrlMatcherInterface</autowiring-type>
80+
<autowiring-type>Symfony\Component\Routing\Matcher\RequestMatcherInterface</autowiring-type>
81+
<autowiring-type>Symfony\Component\Routing\RouterInterface</autowiring-type>
82+
</service>
7883

7984
<service id="router.request_context" class="Symfony\Component\Routing\RequestContext" public="false">
8085
<argument>%router.request_context.base_url%</argument>

src/Symfony/Bundle/FrameworkBundle/Tests/Functional/AutowiringTypesTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Doctrine\Common\Annotations\AnnotationReader;
1515
use Doctrine\Common\Annotations\CachedReader;
16+
use Symfony\Component\Routing\RouterInterface;
1617
use Symfony\Component\Templating\EngineInterface as ComponentEngineInterface;
1718
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface as FrameworkBundleEngineInterface;
1819

@@ -46,6 +47,15 @@ public function testTemplatingAutowiring()
4647
$this->assertInstanceOf(ComponentEngineInterface::class, $autowiredServices->getEngine());
4748
}
4849

50+
public function testRouterAutowiring()
51+
{
52+
static::bootKernel();
53+
$container = static::$kernel->getContainer();
54+
55+
$autowiredServices = $container->get('test.autowiring_types.autowired_services');
56+
$this->assertInstanceOf(RouterInterface::class, $autowiredServices->getRouter());
57+
}
58+
4959
protected static function createKernel(array $options = array())
5060
{
5161
return parent::createKernel(array('test_case' => 'AutowiringTypes') + $options);

src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Bundle/TestBundle/AutowiringTypes/AutowiredServices.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,22 @@
1313

1414
use Doctrine\Common\Annotations\Reader;
1515
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface as FrameworkBundleEngineInterface;
16+
use Symfony\Component\Routing\RouterInterface;
1617
use Symfony\Component\Templating\EngineInterface;
1718

1819
class AutowiredServices
1920
{
2021
private $annotationReader;
2122
private $frameworkBundleEngine;
2223
private $engine;
24+
private $router;
2325

24-
public function __construct(Reader $annotationReader = null, FrameworkBundleEngineInterface $frameworkBundleEngine, EngineInterface $engine)
26+
public function __construct(Reader $annotationReader = null, FrameworkBundleEngineInterface $frameworkBundleEngine, EngineInterface $engine, RouterInterface $router)
2527
{
2628
$this->annotationReader = $annotationReader;
2729
$this->frameworkBundleEngine = $frameworkBundleEngine;
2830
$this->engine = $engine;
31+
$this->router = $router;
2932
}
3033

3134
public function getAnnotationReader()
@@ -42,4 +45,9 @@ public function getEngine()
4245
{
4346
return $this->engine;
4447
}
48+
49+
public function getRouter()
50+
{
51+
return $this->router;
52+
}
4553
}

src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/AutowiringTypes/config.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ services:
55
test.autowiring_types.autowired_services:
66
class: Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\AutowiringTypes\AutowiredServices
77
autowire: true
8+
9+
another_router:
10+
class: Symfony\Bundle\FrameworkBundle\Routing\Router
11+
arguments:
12+
- "@service_container"
13+
814
framework:
915
templating:
1016
engines: ['php']

0 commit comments

Comments
 (0)
0