From b325f9ca8033612a38327e8b2900b694e0ddaa13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20=C5=A0t=C3=ADpek?= Date: Sun, 21 Feb 2016 19:44:16 +0100 Subject: [PATCH] Support autowiring for Doctrine\Common\Annotations\Reader --- .../FrameworkExtension.php | 2 + .../Resources/config/annotations.xml | 4 +- .../Tests/Functional/AutowiringTypesTest.php | 41 +++++++++++++++++++ .../AutowiringTypes/AutowiredServices.php | 29 +++++++++++++ .../app/AutowiringTypes/bundles.php | 18 ++++++++ .../Functional/app/AutowiringTypes/config.yml | 7 ++++ .../AutowiringTypes/no_annotations_cache.yml | 6 +++ 7 files changed, 106 insertions(+), 1 deletion(-) create mode 100644 src/Symfony/Bundle/FrameworkBundle/Tests/Functional/AutowiringTypesTest.php create mode 100644 src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Bundle/TestBundle/AutowiringTypes/AutowiredServices.php create mode 100644 src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/AutowiringTypes/bundles.php create mode 100644 src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/AutowiringTypes/config.yml create mode 100644 src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/AutowiringTypes/no_annotations_cache.yml diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php index e3ab325541931..c73b141012b3e 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php @@ -11,6 +11,7 @@ namespace Symfony\Bundle\FrameworkBundle\DependencyInjection; +use Doctrine\Common\Annotations\Reader; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\Definition; @@ -844,6 +845,7 @@ private function registerAnnotationsConfiguration(array $config, ContainerBuilde ->getDefinition('annotations.cached_reader') ->replaceArgument(1, new Reference('file' !== $config['cache'] ? $config['cache'] : 'annotations.filesystem_cache')) ->replaceArgument(2, $config['debug']) + ->addAutowiringType(Reader::class) ; $container->setAlias('annotation_reader', 'annotations.cached_reader'); } diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/annotations.xml b/src/Symfony/Bundle/FrameworkBundle/Resources/config/annotations.xml index ad469d42f346a..7ccf0da2dcb01 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/annotations.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/annotations.xml @@ -5,7 +5,9 @@ xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> - + + Doctrine\Common\Annotations\Reader + diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/AutowiringTypesTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/AutowiringTypesTest.php new file mode 100644 index 0000000000000..9662e60a2a767 --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/AutowiringTypesTest.php @@ -0,0 +1,41 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Bundle\FrameworkBundle\Tests\Functional; + +use Doctrine\Common\Annotations\AnnotationReader; +use Doctrine\Common\Annotations\CachedReader; + +class AutowiringTypesTest extends WebTestCase +{ + public function testAnnotationReaderAutowiring() + { + static::bootKernel(array('root_config' => 'no_annotations_cache.yml', 'environment' => 'no_annotations_cache')); + $container = static::$kernel->getContainer(); + + $annotationReader = $container->get('test.autowiring_types.autowired_services')->getAnnotationReader(); + $this->assertInstanceOf(AnnotationReader::class, $annotationReader); + } + + public function testCachedAnnotationReaderAutowiring() + { + static::bootKernel(); + $container = static::$kernel->getContainer(); + + $annotationReader = $container->get('test.autowiring_types.autowired_services')->getAnnotationReader(); + $this->assertInstanceOf(CachedReader::class, $annotationReader); + } + + protected static function createKernel(array $options = array()) + { + return parent::createKernel(array('test_case' => 'AutowiringTypes') + $options); + } +} diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Bundle/TestBundle/AutowiringTypes/AutowiredServices.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Bundle/TestBundle/AutowiringTypes/AutowiredServices.php new file mode 100644 index 0000000000000..d013f549996bc --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Bundle/TestBundle/AutowiringTypes/AutowiredServices.php @@ -0,0 +1,29 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\AutowiringTypes; + +use Doctrine\Common\Annotations\Reader; + +class AutowiredServices +{ + private $annotationReader; + + public function __construct(Reader $annotationReader = null) + { + $this->annotationReader = $annotationReader; + } + + public function getAnnotationReader() + { + return $this->annotationReader; + } +} diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/AutowiringTypes/bundles.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/AutowiringTypes/bundles.php new file mode 100644 index 0000000000000..a73987bcc986a --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/AutowiringTypes/bundles.php @@ -0,0 +1,18 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\TestBundle; +use Symfony\Bundle\FrameworkBundle\FrameworkBundle; + +return array( + new FrameworkBundle(), + new TestBundle(), +); diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/AutowiringTypes/config.yml b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/AutowiringTypes/config.yml new file mode 100644 index 0000000000000..9c755e96e8359 --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/AutowiringTypes/config.yml @@ -0,0 +1,7 @@ +imports: + - { resource: ../config/default.yml } + +services: + test.autowiring_types.autowired_services: + class: Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\AutowiringTypes\AutowiredServices + autowire: true diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/AutowiringTypes/no_annotations_cache.yml b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/AutowiringTypes/no_annotations_cache.yml new file mode 100644 index 0000000000000..fec387d87962d --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/AutowiringTypes/no_annotations_cache.yml @@ -0,0 +1,6 @@ +imports: + - { resource: config.yml } + +framework: + annotations: + cache: none pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy