Doctrine\Common\Annotations\FileCacheReader::getMethodAnnotations PHP Method

getMethodAnnotations() public method

{@inheritDoc}
public getMethodAnnotations ( ReflectionMethod $method )
$method ReflectionMethod
    public function getMethodAnnotations(\ReflectionMethod $method)
    {
        $class = $method->getDeclaringClass();
        if (!isset($this->classNameHashes[$class->name])) {
            $this->classNameHashes[$class->name] = sha1($class->name);
        }
        $key = $this->classNameHashes[$class->name] . '#' . $method->getName();
        if (isset($this->loadedAnnotations[$key])) {
            return $this->loadedAnnotations[$key];
        }
        $path = $this->dir . '/' . strtr($key, '\\', '-') . '.cache.php';
        if (!is_file($path)) {
            $annot = $this->reader->getMethodAnnotations($method);
            $this->saveCacheFile($path, $annot);
            return $this->loadedAnnotations[$key] = $annot;
        }
        if ($this->debug && false !== ($filename = $class->getFilename()) && filemtime($path) < filemtime($filename)) {
            @unlink($path);
            $annot = $this->reader->getMethodAnnotations($method);
            $this->saveCacheFile($path, $annot);
            return $this->loadedAnnotations[$key] = $annot;
        }
        return $this->loadedAnnotations[$key] = (include $path);
    }

Usage Example

Exemplo n.º 1
0
 /**
  *  Notes de Marc : onFilterController est un membre de classe qui est automatiquement
  * appelé par le moteur symfony2 (la classe doit avoir été déclarée en Service et doit être
  * instancié dans le Container de symfony) en amont de chaque traitement de requête
  * Dans ce cas particulier, le filtre va employer un autre Service, déclaré dans 
  * 'GaiaService.php' pour tester la présence de certains codes qui sont la preuve de
  * l'autorisation de l'originaire de la requête.
  * @param FilterControllerEvent $event
  * @return type
  * @throws \Exception
  */
 public function onFilterController(FilterControllerEvent $event)
 {
     // Marc inserted this to test if it's being used
     throw new \Exception('SUCCES : Nous sommes dans onFilterController !', 8701);
     //Return if no controller
     if (!is_array($controller = $event->getController())) {
         return;
     }
     list($object, $method) = $controller;
     // the controller could be a proxy, e.g. when using the JMSSecuriyExtraBundle or JMSDiExtraBundle
     $className = ClassUtils::getClass($object);
     $reflectionClass = new \ReflectionClass($className);
     $reflectionMethod = $reflectionClass->getMethod($method);
     $allAnnotations = $this->reader->getMethodAnnotations($reflectionMethod);
     $gaiaAnnotations = array_filter($allAnnotations, function ($annotation) {
         return $annotation instanceof RequiresGaia;
     });
     foreach ($gaiaAnnotations as $gaiaAnnotation) {
         // ... verify
         // throw an exception, catch it using an exception listener
         // then in the exception listener, create a RedirectResponse or something
         // and set it on the $event object
         $gaia = $this->gaia->getGaiaValues('gaia');
         if (strlen($gaia) === 0) {
             throw new \Exception('GAIA non détecté !', 8701);
         }
         if ($gaiaAnnotation->value === 'admin' && $this->security->isAdmin() === false || $gaiaAnnotation->value === 'admin_app' && $this->security->isAdminOrAdminApp() === false) {
             throw new \Exception("Vous n'avez pas les droits nécessaires !", 8702);
         }
     }
 }
All Usage Examples Of Doctrine\Common\Annotations\FileCacheReader::getMethodAnnotations