Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #16: Inherit method support #39

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions DependencyInjection/Compiler/PointcutMatchingPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ private function processDefinition(Definition $definition, $pointcuts, &$interce

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

if ('__construct' === $method->name) {
continue;
}
Expand All @@ -156,13 +155,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;

$proxyFilename = $this->cacheDir.'/'.str_replace('\\', '-', $class->name).'.php';

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