Skip to content

Commit

Permalink
Proposal for review of fix for goaop#335
Browse files Browse the repository at this point in the history
  • Loading branch information
TheCelavi committed Aug 8, 2017
1 parent b6d6881 commit 6acce0e
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
46 changes: 46 additions & 0 deletions src/Aop/Pointcut/ClassDeclaresPointcut.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php
/*
* Go! AOP framework
*
* @copyright Copyright 2016, Lisachenko Alexander <[email protected]>
*
* This source file is subject to the license that is bundled
* with this source code in the file LICENSE.
*/

namespace Go\Aop\Pointcut;

use Go\Aop\Pointcut;
use Go\Aop\PointFilter;

/**
* Pointcut that filters out all class method and properties which are not declared within class
*/
class ClassDeclaresPointcut implements Pointcut
{
use PointcutClassFilterTrait;

/**
* {@inheritdoc}
*/
public function matches($point, $context = null, $instance = null, array $arguments = null)
{
if (!$context instanceof \ReflectionClass) {
return false;
};

if (!($point instanceof \ReflectionMethod) && !($point instanceof \ReflectionProperty)) {
return false;
}

return $point->getDeclaringClass()->getName() === $context->getName();
}

/**
* {@inheritdoc}
*/
public function getKind()
{
return PointFilter::KIND_METHOD | PointFilter::KIND_PROPERTY;
}
}
9 changes: 9 additions & 0 deletions src/Aop/Pointcut/PointcutParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

namespace Go\Aop\Pointcut;

use Dissect\Lexer\TokenStream\TokenStream;
use Dissect\Parser\LALR1\Parser;

/**
Expand All @@ -25,4 +26,12 @@ public function __construct(PointcutGrammar $grammar)
$parseTable = include 'PointcutParseTable.php';
parent::__construct($grammar, $parseTable);
}

/**
* {@inheritdoc}
*/
public function parse(TokenStream $stream)
{
return new AndPointcut(parent::parse($stream), new ClassDeclaresPointcut());
}
}

0 comments on commit 6acce0e

Please sign in to comment.