Beispiel #1
0
 public static function fromReflection(ReflectionParameter $reflection = NULL)
 {
     if (!defined('PHP_VERSION_ID')) {
         $v = explode('.', PHP_VERSION);
         define('PHP_VERSION_ID', $v[0] * 10000 + $v[1] * 100 + $v[2]);
     }
     if ($reflection === null) {
         return null;
     }
     if (func_num_args() > 1) {
         $stack = func_get_arg(1);
     } else {
         $stack = new \ArrayObject();
     }
     $stackExpression = $reflection->getDeclaringClass()->getName() . '::' . $reflection->getDeclaringFunction()->getName() . '(' . $reflection->getPosition() . ')';
     if (isset($stack[$stackExpression])) {
         return $stack[$stackExpression];
     }
     $stack[$stackExpression] = $instance = new Parameter($reflection);
     if (func_num_args() > 2) {
         $reader = func_get_arg(2);
     } else {
         $reader = new AnnotationReader();
     }
     if (func_num_args() > 3) {
         $phpParser = func_get_arg(3);
     } else {
         $phpParser = new PhpParser();
     }
     $instance->name = $reflection->getName();
     $instance->passedByReference = $reflection->isPassedByReference();
     $instance->array = $reflection->isArray();
     $instance->callable = PHP_VERSION_ID >= 50400 ? $reflection->isCallable() : null;
     $instance->position = $reflection->getPosition();
     $instance->optional = $reflection->isOptional();
     $instance->defaultValueAvailable = $reflection->isDefaultValueAvailable();
     $instance->defaultValue = $reflection->isDefaultValueAvailable() ? $reflection->getDefaultValue() : null;
     $instance->defaultValueConstant = PHP_VERSION_ID >= 50500 && $reflection->isDefaultValueAvailable() ? $reflection->isDefaultValueConstant() : null;
     $instance->declaringFunction = Method::fromReflection($reflection->getDeclaringFunction() ? $reflection->getDeclaringFunction() : null, $stack, $reader, $phpParser);
     $instance->declaringClass = Type::fromReflection($reflection->getDeclaringClass() ? $reflection->getDeclaringClass() : null, $stack, $reader, $phpParser);
     if (preg_match('/@param\\s+([a-zA-Z0-9\\\\\\[\\]_]+)\\s+\\$' . preg_quote($instance->name) . '/', $instance->declaringFunction->getDocComment(), $m)) {
         $typeString = $m[1];
     }
     if (isset($typeString)) {
         $instance->type = MixedType::fromString($typeString, $stack, $reader, $phpParser, $instance->declaringClass);
     } elseif ($reflection->getClass()) {
         $instance->type = Type::fromReflection($reflection->getClass(), $stack, $reader, $phpParser, $instance->declaringClass);
     } elseif ($reflection->isArray()) {
         $instance->type = MixedType::fromString('array', $stack, $reader, $phpParser, $instance->declaringClass);
     } else {
         $instance->type = MixedType::getInstance();
     }
     return $instance;
 }
Beispiel #2
0
 /**
  * @return Method
  */
 public function getPrototype()
 {
     if (!$this->prototypeInitialized) {
         try {
             $this->prototype = Method::fromReflection($this->reflection->getPrototype() ? $this->reflection->getPrototype() : null);
         } catch (\ReflectionException $e) {
             $this->prototype = null;
         }
         $this->prototypeInitialized = true;
     }
     return $this->prototype;
 }
Beispiel #3
0
 /**
  * @return Method[]
  */
 public function getMethods()
 {
     if (!$this->methodsInitialized) {
         $this->methods = array();
         foreach ($this->reflection->getMethods() as $key => $value) {
             $this->methods[$key] = Method::fromReflection($value);
         }
         $this->methodsInitialized = true;
     }
     return $this->methods;
 }