diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php index 17945a62015b..c4c65144a52f 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; @@ -851,6 +852,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 ad469d42f346..7ccf0da2dcb0 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 000000000000..9662e60a2a76 --- /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 000000000000..d013f549996b --- /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 000000000000..a73987bcc986 --- /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 000000000000..9c755e96e835 --- /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 000000000000..fec387d87962 --- /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