コード例 #1
0
ファイル: Handler.php プロジェクト: villfa/checktypes
 private function getAnnotations(\ReflectionFunctionAbstract $func, $name)
 {
     $types = array();
     $annotations = new Annotations($func);
     if ($annotations->hasAnnotation($name)) {
         $types = (array) $annotations[$name];
     }
     return $types;
 }
コード例 #2
0
 /**
  * Retrieve annotation set for given reflector.  Reflector can either be the
  * name of a class to reflect or an instance of Reflector that implements
  * the getDocComment() method. To create an empty Annotations object simply
  * call this method with no arguments.
  *
  * @param mixed $reflector
  * @return Annotations
  */
 public function get($reflector = null)
 {
     $docComment = Annotations::parseDocComment($reflector);
     $cacheKey = md5((string) $docComment);
     if (array_key_exists($cacheKey, $this->_cache)) {
         return $this->_cache[$cacheKey];
     }
     $annotations = new Annotations($docComment);
     $this->_cache[$cacheKey] = $annotations;
     return $annotations;
 }
コード例 #3
0
ファイル: Annotation.php プロジェクト: frnks/meister
 /**
  * @param $controller
  * @param $method
  * @return mixed
  * @throws \Exception
  */
 public function validation($controller, $method, $options)
 {
     $classReflector = new \ReflectionClass($controller);
     $classAnnotations = new Annotations($classReflector);
     $methodAnnotations = array();
     foreach ($classReflector->getMethods() as $methodReflector) {
         $methodAnnotations[$methodReflector->getName()] = new Annotations($methodReflector);
     }
     $interfaces = class_implements($controller);
     if (isset($interfaces['Meister\\Meister\\interfaces\\MeisterRestInterface'])) {
         $return['rest'] = true;
     } else {
         $return['rest'] = false;
     }
     if ($return['rest']) {
         $method = $_SERVER['REQUEST_METHOD'];
         $method = strtolower($method);
     }
     /**
      * Valida annotations classe
      */
     if ($this->config['authentication']) {
         if ($classAnnotations->hasAnnotation('notauthenticated') === false) {
             if (!$this->authenticatedValidation(true)) {
                 if (array_key_exists($method, $methodAnnotations) && !$methodAnnotations[$method]->hasAnnotation('notauthenticated') === true) {
                     throw new \Exception("Not authenticated", 403);
                 }
             }
         }
     } else {
         if ($classAnnotations->hasAnnotation('authenticated') === true) {
             if (!$this->authenticatedValidation(true)) {
                 if (array_key_exists($method, $methodAnnotations) && !$methodAnnotations[$method]->hasAnnotation('notauthenticated') === true) {
                     throw new \Exception("Not authenticated", 403);
                 }
             }
         }
     }
     if ($classAnnotations->hasAnnotation('permission') === true) {
         $this->checkPermission($classAnnotations['permission']);
     }
     if ($classAnnotations->hasAnnotation('post') === true) {
         $return['post'] = true;
     } else {
         $return['post'] = false;
     }
     /**
      * Valida annotations metodos
      */
     if (array_key_exists($method, $methodAnnotations) && $methodAnnotations[$method]->hasAnnotation('request') === true) {
         $this->requestValidation($methodAnnotations[$method]['request']);
     }
     if (array_key_exists($method, $methodAnnotations) && $methodAnnotations[$method]->hasAnnotation('authenticated') === true) {
         $this->authenticatedValidation();
     }
     if (array_key_exists($method, $methodAnnotations) && $methodAnnotations[$method]->hasAnnotation('notview') === true) {
         $return['view'] = false;
     } else {
         $return['view'] = true;
     }
     if (array_key_exists($method, $methodAnnotations) && $methodAnnotations[$method]->hasAnnotation('api') === true) {
         $return['api'] = true;
     } else {
         $return['api'] = false;
     }
     if (array_key_exists($method, $methodAnnotations) && $methodAnnotations[$method]->hasAnnotation('permission') === true) {
         $this->checkPermission($methodAnnotations[$method]['permission']);
     }
     /**
      * Valida Options
      */
     if (array_key_exists('request', $options)) {
         $this->requestValidation($options['request']);
     }
     if (array_key_exists('permission', $options)) {
         $this->checkPermission($options['permission']);
     }
     if (array_key_exists('authenticated', $options)) {
         if ($options['authenticated']) {
             $this->authenticatedValidation();
         }
     }
     if (array_key_exists('notview', $options)) {
         $return['view'] = false;
     }
     if (array_key_exists('api', $options)) {
         $return['api'] = true;
     }
     foreach ($return as $k => $r) {
         $this->app[$k] = $r;
     }
 }