Esempio n. 1
0
 /**
  * Verifies a reflection function or method
  *
  * @param  php.ReflectionFunctionAbstract $value
  * @param  [lang.Type] $signature
  * @param  function(string): var $value A function to invoke when verification fails
  * @param  php.ReflectionClass $class Class to get details from, optionally
  * @return var
  */
 protected function verify($r, $signature, $false, $class = null)
 {
     if (null !== $signature && sizeof($signature) < $r->getNumberOfRequiredParameters()) {
         return $false('Required signature length mismatch, expecting ' . sizeof($signature) . ', have ' . $r->getNumberOfParameters());
     }
     $details = $class ? XPClass::detailsForMethod($class->getName(), $r->getName()) : null;
     if (isset($details[DETAIL_RETURNS])) {
         $returns = Type::forName($details[DETAIL_RETURNS]);
         if (!$this->returns->equals($returns) && !$this->returns->isAssignableFrom($returns)) {
             return $false('Return type mismatch, expecting ' . $this->returns->getName() . ', have ' . $returns->getName());
         }
     }
     if (null === $signature) {
         return true;
     }
     $params = $r->getParameters();
     foreach ($signature as $i => $type) {
         if (!isset($params[$i])) {
             return $false('No parameter #' . ($i + 1));
         }
         if (isset($details[DETAIL_ARGUMENTS][$i])) {
             $param = Type::forName($details[DETAIL_ARGUMENTS][$i]);
             if (!$type->isAssignableFrom($param)) {
                 return $false('Parameter #' . ($i + 1) . ' not a ' . $param->getName() . ' type: ' . $type->getName());
             }
         } else {
             $param = $params[$i];
             if ($param->isArray()) {
                 if (!$type->equals(Primitive::$ARRAY) && !$type instanceof ArrayType && !$type instanceof MapType) {
                     return $false('Parameter #' . ($i + 1) . ' not an array type: ' . $type->getName());
                 }
             } else {
                 if ($param->isCallable()) {
                     if (!$type instanceof FunctionType) {
                         return $false('Parameter #' . ($i + 1) . ' not a function type: ' . $type->getName());
                     }
                 } else {
                     if (null !== ($class = $param->getClass())) {
                         if (!$type->isAssignableFrom(new XPClass($class))) {
                             return $false('Parameter #' . ($i + 1) . ' not a ' . $class->getName() . ': ' . $type->getName());
                         }
                     }
                 }
             }
         }
     }
     return true;
 }
Esempio n. 2
0
 /**
  * Retrieve all of a method's annotations
  *
  * @return [:var] annotations
  */
 public function getAnnotations()
 {
     $details = XPClass::detailsForMethod($this->_reflect->getDeclaringClass(), $this->_reflect->getName());
     return $details ? $details[DETAIL_ANNOTATIONS] : [];
 }
Esempio n. 3
0
 /**
  * Retrieve all of a method's annotations
  *
  * @return  var[] annotations
  */
 public function getAnnotations()
 {
     $n = '$' . $this->_reflect->getName();
     if (!($details = XPClass::detailsForMethod($this->_details[0], $this->_details[1])) || !isset($details[DETAIL_TARGET_ANNO][$n])) {
         // Unknown or unparseable
         return array();
     }
     return $details[DETAIL_TARGET_ANNO][$n];
 }