Skip to content

Commit

Permalink
Fixes schmittjoh#16: Inherit method support
Browse files Browse the repository at this point in the history
  • Loading branch information
Florian Pfitzer committed Feb 25, 2013
1 parent 7018357 commit dd9041c
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 5 deletions.
6 changes: 4 additions & 2 deletions DependencyInjection/Compiler/PointcutMatchingPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ private function processDefinition(Definition $definition, $pointcuts, &$interce

$classAdvices = array();
foreach (ReflectionUtils::getOverrideableMethods($class) as $method) {

if ('__construct' === $method->name) {
continue;
}
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}
16 changes: 16 additions & 0 deletions Tests/DependencyInjection/Compiler/Fixture/ParentService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php
namespace JMS\AopBundle\Tests\DependencyInjection\Compiler\Fixture;


class ParentService
{
public function parentDelete()
{
return true;
}

public function overwrittenDelete()
{
return false;
}
}
7 changes: 6 additions & 1 deletion Tests/DependencyInjection/Compiler/Fixture/TestService.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

namespace JMS\AopBundle\Tests\DependencyInjection\Compiler\Fixture;

class TestService
class TestService extends ParentService
{
public function add()
{
Expand All @@ -29,4 +29,9 @@ public function delete()
{
return true;
}

public function overwrittenDelete()
{
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ public function testProcess()
$this->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()
Expand Down

0 comments on commit dd9041c

Please sign in to comment.