Created
June 20, 2012 11:27
-
-
Save khepin/2959435 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Khepin\UserValidatorBundle\Aop; | |
use JMS\AopBundle\Aop\PointcutInterface; | |
use Doctrine\Common\Annotations\Reader; | |
/** | |
* Pointcut for all calls to a method that requires validating the user | |
*/ | |
class Pointcut implements PointcutInterface | |
{ | |
private $reader; | |
private static $annotation_class = 'Khepin\UserValidatorBundle\Annotation\ValidateUser'; | |
public function __construct(Reader $reader) | |
{ | |
$this->reader = $reader; | |
} | |
public function matchesClass(\ReflectionClass $class) | |
{ | |
return $class->isSubclassOf('Symfony\Bundle\FrameworkBundle\Controller\Controller'); | |
} | |
/** | |
* Match methods that have the @ValidateUser Annotation | |
* @param ReflectionMethod $method | |
* @return bool | |
*/ | |
public function matchesMethod(\ReflectionMethod $method) | |
{ | |
$annotation = $this->reader->getMethodAnnotation($method, self::$annotation_class); | |
return !is_null($annotation); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment