Skip to content

Instantly share code, notes, and snippets.

@khepin
Created June 20, 2012 11:27
Show Gist options
  • Save khepin/2959435 to your computer and use it in GitHub Desktop.
Save khepin/2959435 to your computer and use it in GitHub Desktop.
<?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