Exemplo n.º 1
0
 public function testParemeterReturn()
 {
     $method = new MethodReflection('ZendTest\\Code\\Reflection\\TestAsset\\TestSampleClass2', 'getProp2');
     $parameters = $method->getParameters();
     $this->assertEquals(2, count($parameters));
     $this->assertInstanceOf('Zend\\Code\\Reflection\\ParameterReflection', array_shift($parameters));
 }
Exemplo n.º 2
0
 /**
  * @param  MethodReflection $reflectionMethod
  * @return MethodGenerator
  */
 public static function fromReflection(MethodReflection $reflectionMethod)
 {
     $method = new static();
     $declaringClass = $reflectionMethod->getDeclaringClass();
     $method->setSourceContent($reflectionMethod->getContents(false));
     $method->setSourceDirty(false);
     if ($reflectionMethod->getDocComment() != '') {
         $method->setDocBlock(DocBlockGenerator::fromReflection($reflectionMethod->getDocBlock()));
     }
     $method->setFinal($reflectionMethod->isFinal());
     if ($reflectionMethod->isPrivate()) {
         $method->setVisibility(self::VISIBILITY_PRIVATE);
     } elseif ($reflectionMethod->isProtected()) {
         $method->setVisibility(self::VISIBILITY_PROTECTED);
     } else {
         $method->setVisibility(self::VISIBILITY_PUBLIC);
     }
     $method->setInterface($declaringClass->isInterface());
     $method->setStatic($reflectionMethod->isStatic());
     $method->setName($reflectionMethod->getName());
     foreach ($reflectionMethod->getParameters() as $reflectionParameter) {
         $method->setParameter(ParameterGenerator::fromReflection($reflectionParameter));
     }
     $method->setBody(static::clearBodyIndention($reflectionMethod->getBody()));
     return $method;
 }
Exemplo n.º 3
0
    /**
     * Return method argument prototype
     *
     * @return string
     */
    public function getPrototype()
    {
        $params = array();

        $reflectionParams = $this->getParameterTags();

        foreach ($this->reflection->getParameters() as $index => $param) {
            $types = '';
            if (isset($reflectionParams[$index])) {
                $type  = $reflectionParams[$index]->getType();
                $types = $this->resolveTypes($type);
            }

            $default = '';
            if ($param->isOptional()) {
                $defaultValue = var_export($param->getDefaultValue(), 1);
                $defaultValue = $this->resolveTypes($defaultValue);

                // Skip null values, but report all others
                if ('null' != strtolower($defaultValue)) {
                    $default = ' = ' . $this->resolveTypes($defaultValue);
                }
            }

            $prototype = sprintf('%s $%s%s', $types, $param->getName(), $default);
            $params[]  = $prototype;
        }

        return implode(', ', $params);
    }
Exemplo n.º 4
0
 /**
  * Process method parameters
  *
  * @param array $def
  * @param Reflection\ClassReflection $rClass
  * @param Reflection\MethodReflection $rMethod
  */
 protected function processParams(&$def, Reflection\ClassReflection $rClass, Reflection\MethodReflection $rMethod)
 {
     if (count($rMethod->getParameters()) === 0) {
         return;
     }
     $methodName = $rMethod->getName();
     // @todo annotations here for alternate names?
     $def['parameters'][$methodName] = array();
     foreach ($rMethod->getParameters() as $p) {
         /** @var $p \ReflectionParameter  */
         $actualParamName = $p->getName();
         $fqName = $rClass->getName() . '::' . $rMethod->getName() . ':' . $p->getPosition();
         $def['parameters'][$methodName][$fqName] = array();
         // set the class name, if it exists
         $def['parameters'][$methodName][$fqName][] = $actualParamName;
         $def['parameters'][$methodName][$fqName][] = $p->getClass() !== null ? $p->getClass()->getName() : null;
         $def['parameters'][$methodName][$fqName][] = !$p->isOptional();
         $def['parameters'][$methodName][$fqName][] = $p->isOptional() && $p->isDefaultValueAvailable() ? $p->getDefaultValue() : null;
     }
 }
Exemplo n.º 5
0
 /**
  * Process class method parameters
  *
  * @param array $def
  * @param Zend\Code\Reflection\ClassReflection $rClass
  * @param Zend\Code\Reflection\MethodReflection $rMethod
  */
 protected function processParams(&$def, Reflection\ClassReflection $rClass, Reflection\MethodReflection $rMethod)
 {
     if (count($rMethod->getParameters()) === 0) {
         return;
     }
     parent::processParams($def, $rClass, $rMethod);
     $methodName = $rMethod->getName();
     /** @var $p \ReflectionParameter */
     foreach ($rMethod->getParameters() as $p) {
         $fqName = $rClass->getName() . '::' . $rMethod->getName() . ':' . $p->getPosition();
         $def['parameters'][$methodName][$fqName][] = $p->isOptional() && $p->isDefaultValueAvailable() ? $p->getDefaultValue() : null;
     }
 }