From dd9041cc9342861cbde91833afe9ece18b6ff5f4 Mon Sep 17 00:00:00 2001 From: Florian Pfitzer Date: Mon, 25 Feb 2013 11:58:19 +0100 Subject: [PATCH] Fixes #16: Inherit method support --- .../Compiler/PointcutMatchingPass.php | 6 ++++-- .../Compiler/Fixture/LoggingPointcut.php | 2 +- .../Compiler/Fixture/ParentService.php | 16 ++++++++++++++++ .../Compiler/Fixture/TestService.php | 7 ++++++- .../Compiler/PointcutMatchingPassTest.php | 4 +++- 5 files changed, 30 insertions(+), 5 deletions(-) create mode 100755 Tests/DependencyInjection/Compiler/Fixture/ParentService.php diff --git a/DependencyInjection/Compiler/PointcutMatchingPass.php b/DependencyInjection/Compiler/PointcutMatchingPass.php index 5cd149e..e1ba039 100644 --- a/DependencyInjection/Compiler/PointcutMatchingPass.php +++ b/DependencyInjection/Compiler/PointcutMatchingPass.php @@ -132,7 +132,6 @@ private function processDefinition(Definition $definition, $pointcuts, &$interce $classAdvices = array(); foreach (ReflectionUtils::getOverrideableMethods($class) as $method) { - if ('__construct' === $method->name) { continue; } @@ -149,13 +148,16 @@ private function processDefinition(Definition $definition, $pointcuts, &$interce } $classAdvices[$method->name] = $advices; + $className = ClassUtils::getUserClass($method->getDeclaringClass()->getName()); + $interceptors[$className][$method->name] = $advices; + } + if (empty($classAdvices)) { return; } - $interceptors[ClassUtils::getUserClass($class->name)] = $classAdvices; $generator = new InterceptionGenerator(); $generator->setFilter(function(\ReflectionMethod $method) use ($classAdvices) { diff --git a/Tests/DependencyInjection/Compiler/Fixture/LoggingPointcut.php b/Tests/DependencyInjection/Compiler/Fixture/LoggingPointcut.php index 1a2814f..7a77508 100644 --- a/Tests/DependencyInjection/Compiler/Fixture/LoggingPointcut.php +++ b/Tests/DependencyInjection/Compiler/Fixture/LoggingPointcut.php @@ -29,6 +29,6 @@ public function matchesClass(\ReflectionClass $class) public function matchesMethod(\ReflectionMethod $method) { - return false !== strpos($method->name, 'delete'); + return false !== stripos($method->name, 'delete'); } } diff --git a/Tests/DependencyInjection/Compiler/Fixture/ParentService.php b/Tests/DependencyInjection/Compiler/Fixture/ParentService.php new file mode 100755 index 0000000..c7dc915 --- /dev/null +++ b/Tests/DependencyInjection/Compiler/Fixture/ParentService.php @@ -0,0 +1,16 @@ +assertInstanceOf('JMS\AopBundle\Tests\DependencyInjection\Compiler\Fixture\TestService', $service); $this->assertTrue($service->add()); $this->assertTrue($service->delete()); - $this->assertEquals(array('delete'), $container->get('interceptor')->getLog()); + $this->assertTrue($service->parentDelete()); + $this->assertTrue($service->overwrittenDelete()); + $this->assertEquals(array('delete', 'parentDelete', 'overwrittenDelete'), $container->get('interceptor')->getLog()); } protected function setUp()