[FrameworkBundle] Add more autowiring aliases

This commit is contained in:
Robin Chalas 2017-02-02 23:47:41 +01:00
parent 2e13d4efa6
commit c3a2141a45
7 changed files with 58 additions and 3 deletions

View File

@ -105,6 +105,7 @@
<service id="cache.global_clearer" parent="cache.default_clearer" />
<service id="cache.app_clearer" alias="cache.default_clearer" />
<service id="Psr\Cache\CacheItemPoolInterface" alias="cache.app" public="false" />
</services>
</container>

View File

@ -13,6 +13,9 @@ namespace Symfony\Bundle\FrameworkBundle\Tests\Functional;
use Doctrine\Common\Annotations\AnnotationReader;
use Doctrine\Common\Annotations\CachedReader;
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
use Symfony\Component\Security\Core\Authorization\AccessDecisionManager;
use Symfony\Component\Security\Core\Authorization\TraceableAccessDecisionManager;
use Symfony\Component\Templating\EngineInterface as ComponentEngineInterface;
use Symfony\Component\HttpKernel\Debug\TraceableEventDispatcher;
use Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher;
@ -63,6 +66,30 @@ class AutowiringTypesTest extends WebTestCase
$this->assertInstanceOf(TraceableEventDispatcher::class, $autowiredServices->getDispatcher(), 'The debug.event_dispatcher service should be injected if the debug is enabled');
}
public function testAccessDecisionManagerAutowiring()
{
static::bootKernel(array('debug' => false));
$container = static::$kernel->getContainer();
$autowiredServices = $container->get('test.autowiring_types.autowired_services');
$this->assertInstanceOf(AccessDecisionManager::class, $autowiredServices->getAccessDecisionManager(), 'The security.access.decision_manager service should be injected in debug mode');
static::bootKernel(array('debug' => true));
$container = static::$kernel->getContainer();
$autowiredServices = $container->get('test.autowiring_types.autowired_services');
$this->assertInstanceOf(TraceableAccessDecisionManager::class, $autowiredServices->getAccessDecisionManager(), 'The debug.security.access.decision_manager service should be injected in non-debug mode');
}
public function testCacheAutowiring()
{
static::bootKernel();
$container = static::$kernel->getContainer();
$autowiredServices = $container->get('test.autowiring_types.autowired_services');
$this->assertInstanceOf(FilesystemAdapter::class, $autowiredServices->getCachePool());
}
protected static function createKernel(array $options = array())
{
return parent::createKernel(array('test_case' => 'AutowiringTypes') + $options);

View File

@ -12,7 +12,9 @@
namespace Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\AutowiringTypes;
use Doctrine\Common\Annotations\Reader;
use Psr\Cache\CacheItemPoolInterface;
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface as FrameworkBundleEngineInterface;
use Symfony\Component\Security\Core\Authorization\AccessDecisionManagerInterface;
use Symfony\Component\Templating\EngineInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
@ -22,13 +24,17 @@ class AutowiredServices
private $frameworkBundleEngine;
private $engine;
private $dispatcher;
private $accessDecisionManager;
private $cachePool;
public function __construct(Reader $annotationReader = null, FrameworkBundleEngineInterface $frameworkBundleEngine, EngineInterface $engine, EventDispatcherInterface $dispatcher)
public function __construct(Reader $annotationReader = null, FrameworkBundleEngineInterface $frameworkBundleEngine, EngineInterface $engine, EventDispatcherInterface $dispatcher, AccessDecisionManagerInterface $accessDecisionManager, CacheItemPoolInterface $cachePool)
{
$this->annotationReader = $annotationReader;
$this->frameworkBundleEngine = $frameworkBundleEngine;
$this->engine = $engine;
$this->dispatcher = $dispatcher;
$this->accessDecisionManager = $accessDecisionManager;
$this->cachePool = $cachePool;
}
public function getAnnotationReader()
@ -50,4 +56,14 @@ class AutowiredServices
{
return $this->dispatcher;
}
public function getAccessDecisionManager()
{
return $this->accessDecisionManager;
}
public function getCachePool()
{
return $this->cachePool;
}
}

View File

@ -11,8 +11,10 @@
use Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\TestBundle;
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
use Symfony\Bundle\SecurityBundle\SecurityBundle;
return array(
new FrameworkBundle(),
new SecurityBundle(),
new TestBundle(),
);

View File

@ -8,3 +8,10 @@ services:
framework:
templating:
engines: ['php']
security:
providers:
dummy:
memory: ~
firewalls:
dummy:
security: false

View File

@ -40,7 +40,7 @@
"symfony/css-selector": "~2.8|~3.0",
"symfony/dom-crawler": "~2.8|~3.0",
"symfony/polyfill-intl-icu": "~1.0",
"symfony/security": "~2.8|~3.0",
"symfony/security": "~3.3",
"symfony/form": "~2.8.16|~3.1.9|^3.2.2",
"symfony/expression-language": "~2.8|~3.0",
"symfony/process": "~2.8|~3.0",
@ -55,7 +55,8 @@
"doctrine/annotations": "~1.0",
"phpdocumentor/reflection-docblock": "^3.0",
"twig/twig": "~1.26|~2.0",
"sensio/framework-extra-bundle": "^3.0.2"
"sensio/framework-extra-bundle": "^3.0.2",
"symfony/security-bundle": "~3.3"
},
"conflict": {
"phpdocumentor/reflection-docblock": "<3.0",

View File

@ -67,6 +67,7 @@
<service id="security.access.decision_manager" class="Symfony\Component\Security\Core\Authorization\AccessDecisionManager" public="false">
<argument type="collection" />
</service>
<service id="Symfony\Component\Security\Core\Authorization\AccessDecisionManagerInterface" alias="security.access.decision_manager" public="false" />
<service id="security.role_hierarchy" class="Symfony\Component\Security\Core\Role\RoleHierarchy" public="false">
<argument>%security.role_hierarchy.roles%</argument>