Skip to content

Commit a40cc7e

Browse files
angelovlisachenko
authored andcommitted
Autoconfiguring aspects in Symfony 3.3+ (#19)
1 parent 4181ee7 commit a40cc7e

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

DependencyInjection/GoAopExtension.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
namespace Go\Symfony\GoAopBundle\DependencyInjection;
1212

1313

14+
use Go\Aop\Aspect;
1415
use Symfony\Component\Config\FileLocator;
1516
use Symfony\Component\DependencyInjection\ContainerBuilder;
1617
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
@@ -71,5 +72,12 @@ public function load(array $config, ContainerBuilder $container)
7172
->getDefinition('goaop.bridge.doctrine.metadata_load_interceptor')
7273
->addTag('doctrine.event_subscriber');
7374
}
75+
76+
// Service autoconfiguration is available in Symfony 3.3+
77+
if (method_exists($container, 'registerForAutoconfiguration')) {
78+
$container
79+
->registerForAutoconfiguration(Aspect::class)
80+
->addTag('goaop.aspect');
81+
}
7482
}
7583
}

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,9 @@ services:
153153
- { name: goaop.aspect }
154154
```
155155
156+
If you're using Symfony 3.3+ with autowired and autoconfigured services, your aspects will be
157+
registered automatically.
158+
156159
Known issues and workarounds
157160
----------------------------
158161

Tests/DependencyInjection/GoAopExtensionTest.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010

1111
namespace Go\Symfony\GoAopBundle\Tests\DependencyInjection;
1212

13+
use Go\Aop\Aspect;
1314
use Go\Symfony\GoAopBundle\DependencyInjection\GoAopExtension;
1415
use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractExtensionTestCase;
15-
use Symfony\Component\DependencyInjection\Definition;
1616

1717
/**
1818
* Class GoAopExtensionTest
@@ -89,6 +89,22 @@ public function itEnablesDoctrineSupport()
8989
$this->assertContainerBuilderHasServiceDefinitionWithTag('goaop.bridge.doctrine.metadata_load_interceptor', 'doctrine.event_subscriber');
9090
}
9191

92+
/**
93+
* @test
94+
*/
95+
public function itRegistersAspectInterfaceForAutoconfiguration()
96+
{
97+
if (!method_exists($this->container, 'getAutoconfiguredInstanceof')) {
98+
$this->markTestSkipped('Service autoconfiguration is available in Symfony 3.3+');
99+
}
100+
101+
$this->load();
102+
103+
$autoconfigure = $this->container->getAutoconfiguredInstanceof();
104+
105+
$this->assertTrue($autoconfigure[Aspect::class]->hasTag('goaop.aspect'));
106+
}
107+
92108
/**
93109
* {@inheritdoc}
94110
*/

0 commit comments

Comments
 (0)