8000 Support autowiring for Doctrine\Common\Annotations\Reader · symfony/symfony@b325f9c · GitHub
[go: up one dir, main page]

Skip to content

Commit b325f9c

Browse files
committed
Support autowiring for Doctrine\Common\Annotations\Reader
1 parent 0813705 commit b325f9c

File tree

7 files changed

+106
-1
lines changed
  • Tests/Functional
  • 7 files changed

    +106
    -1
    lines changed

    src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

    Lines changed: 2 additions & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -11,6 +11,7 @@
    1111

    1212
    namespace Symfony\Bundle\FrameworkBundle\DependencyInjection;
    1313

    14+
    use Doctrine\Common\Annotations\Reader;
    1415
    use Symfony\Component\DependencyInjection\ContainerBuilder;
    1516
    use Symfony\Component\DependencyInjection\ContainerInterface;
    1617
    use Symfony\Component\DependencyInjection\Definition;
    @@ -844,6 +845,7 @@ private function registerAnnotationsConfiguration(array $config, ContainerBuilde
    844845
    ->getDefinition('annotations.cached_reader')
    845846
    ->replaceArgument(1, new Reference('file' !== $config['cache'] ? $config['cache'] : 'annotations.filesystem_cache'))
    846847
    ->replaceArgument(2, $config['debug'])
    848+
    ->addAutowiringType(Reader::class)
    847849
    ;
    848850
    $container->setAlias('annotation_reader', 'annotations.cached_reader');
    849851
    }

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

    Lines changed: 3 additions & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -5,7 +5,9 @@
    55
    xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
    66

    77
    <services>
    8-
    <service id="annotations.reader" class="Doctrine\Common\Annotations\AnnotationReader" public="false" />
    8+
    <service id="annotations.reader" class="Doctrine\Common\Annotations\AnnotationReader" public="false">
    9+
    <autowiring-type>Doctrine\Common\Annotations\Reader</autowiring-type>
    10+
    </service>
    911

    1012
    <service id="annotations.cached_reader" class="Doctrine\Common\Annotations\CachedReader" public="false">
    1113
    <argument type="service" id="annotations.reader" />
    Lines changed: 41 additions & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -0,0 +1,41 @@
    1+
    <?php
    2+
    3+
    /*
    4+
    * This file is part of the Symfony package.
    5+
    *
    6+
    * (c) Fabien Potencier <fabien@symfony.com>
    7+
    *
    8+
    * For the full copyright and license information, please view the LICENSE
    9+
    * file that was distributed with this source code.
    10+
    */
    11+
    12+
    namespace Symfony\Bundle\FrameworkBundle\Tests\Functional;
    13+
    14+
    use Doctrine\Common\Annotations\AnnotationReader;
    15+
    use Doctrine\Common\Annotations\CachedReader;
    16+
    17+
    class AutowiringTypesTest extends WebTestCase
    18+
    {
    19+ public function testAnnotationReaderAutowiring()
    20+
    {
    21+
    static::bootKernel(array('root_config' => 'no_annotations_cache.yml', 'environment' => 'no_annotations_cache'));
    22+
    $container = static::$kernel->getContainer();
    23+
    24+
    $annotationReader = $container->get('test.autowiring_types.autowired_services')->getAnnotationReader();
    25+
    $this->assertInstanceOf(AnnotationReader::class, $annotationReader);
    26+
    }
    27+
    28+
    public function testCachedAnnotationReaderAutowiring()
    29+
    {
    30+
    static::bootKernel();
    31+
    $container = static::$kernel->getContainer();
    32+
    33+
    $annotationReader = $container->get('test.autowiring_types.autowired_services')->getAnnotationReader();
    34+
    $this->assertInstanceOf(CachedReader::class, $annotationReader);
    35+
    }
    36+
    37+
    protected static function createKernel(array $options = array())
    38+
    {
    39+
    return parent::createKernel(array('test_case' => 'AutowiringTypes') + $options);
    40+
    }
    41+
    }
    Original file line numberDiff line numberDiff line change
    @@ -0,0 +1,29 @@
    1+
    <?php
    2+
    3+
    /*
    4+
    * This file is part of the Symfony package.
    5+
    *
    6+
    * (c) Fabien Potencier <fabien@symfony.com>
    7+
    *
    8+
    * For the full copyright and license information, please view the LICENSE
    9+
    * file that was distributed with this source code.
    10+
    */
    11+
    12+
    namespace Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\AutowiringTypes;
    13+
    14+
    use Doctrine\Common\Annotations\Reader;
    15+
    16+
    class AutowiredServices
    17+
    {
    18+
    private $annotationReader;
    19+
    20+
    public function __construct(Reader $annotationReader = null)
    21+
    {
    22+
    $this->annotationReader = $annotationReader;
    23+
    }
    24+
    25+
    public function getAnnotationReader()
    26+
    {
    27+
    return $this->annotationReader;
    28+
    }
    29+
    }
    Lines changed: 18 additions & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -0,0 +1,18 @@
    1+
    <?php
    2+
    3+
    /*
    4+
    * This file is part of the Symfony package.
    5+
    *
    6+
    * (c) Fabien Potencier <fabien@symfony.com>
    7+
    *
    8+
    * For the full copyright and license information, please view the LICENSE
    9+
    * file that was distributed with this source code.
    10+
    */
    11+
    12+
    use Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\TestBundle;
    13+
    use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
    14+
    15+
    return array(
    16+
    new FrameworkBundle(),
    17+
    new TestBundle(),
    18+
    );
    Lines changed: 7 additions & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -0,0 +1,7 @@
    1+
    imports:
    2+
    - { resource: ../config/default.yml }
    3+
    4+
    services:
    5+
    test.autowiring_types.autowired_services:
    6+
    class: Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\AutowiringTypes\AutowiredServices
    7+
    autowire: true
    Lines changed: 6 additions & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -0,0 +1,6 @@
    1+
    imports:
    2+
    - { resource: config.yml }
    3+
    4+
    framework:
    5+
    annotations:
    6+
    cache: none

    0 commit comments

    Comments
     (0)
    0