fromReflection() публичный статический Метод

public static fromReflection ( Zend\Code\Reflection\ParameterReflection $reflectionParameter ) : ParameterGenerator
$reflectionParameter Zend\Code\Reflection\ParameterReflection
Результат ParameterGenerator
Пример #1
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);
     $method->setReturnType(self::extractReturnTypeFromMethodReflection($reflectionMethod));
     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->setReturnsReference($reflectionMethod->returnsReference());
     $method->setName($reflectionMethod->getName());
     foreach ($reflectionMethod->getParameters() as $reflectionParameter) {
         $method->setParameter(ParameterGenerator::fromReflection($reflectionParameter));
     }
     $method->setBody(static::clearBodyIndention($reflectionMethod->getBody()));
     return $method;
 }
Пример #2
0
    /**
     * fromReflection()
     *
     * @param  MethodReflection $reflectionMethod
     * @return MethodGenerator
     */
    public static function fromReflection(MethodReflection $reflectionMethod)
    {
        $method = new self();

        $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->setStatic($reflectionMethod->isStatic());

        $method->setName($reflectionMethod->getName());

        foreach ($reflectionMethod->getParameters() as $reflectionParameter) {
            $method->setParameter(ParameterGenerator::fromReflection($reflectionParameter));
        }

        $method->setBody($reflectionMethod->getBody());

        return $method;
    }
Пример #3
0
 /**
  * @dataProvider dataFromReflectionGenerate
  * @param string $methodName
  * @param string $expectedCode
  */
 public function testFromReflectionGenerate($methodName, $expectedCode)
 {
     //$this->markTestSkipped('Test may not be necessary any longer');
     $reflectionParameter = $this->getFirstReflectionParameter($methodName);
     $codeGenParam = ParameterGenerator::fromReflection($reflectionParameter);
     $this->assertEquals($expectedCode, $codeGenParam->generate());
 }
    /**
     * @dataProvider dataFromReflectionGenerate
     * @param string $methodName
     * @param string $expectedCode
     */
    public function testFromReflectionGenerate($methodName, $expectedCode)
    {
        $reflectionParameter = $this->getFirstReflectionParameter($methodName);
        $codeGenParam = ParameterGenerator::fromReflection($reflectionParameter);

        $this->assertEquals($expectedCode, $codeGenParam->generate());
    }
Пример #5
0
 /**
  * @group 5193
  */
 public function testTypehintsWithNamespaceInNamepsacedClassReturnTypewithBackslash()
 {
     require_once __DIR__ . '/TestAsset/NamespaceTypeHintClass.php';
     $reflClass = new \Zend\Code\Reflection\ClassReflection('Namespaced\\TypeHint\\Bar');
     $params = $reflClass->getMethod('method')->getParameters();
     $param = ParameterGenerator::fromReflection($params[0]);
     $this->assertEquals('\\OtherNamespace\\ParameterClass', $param->getType());
 }
Пример #6
0
 /**
  * @override Enforces generation of \ProxyManager\Generator\MethodGenerator.
  *
  * {@inheritDoc}
  * @throws \Zend\Code\Generator\Exception\InvalidArgumentException
  */
 public static function fromReflection(MethodReflection $reflectionMethod) : MethodGenerator
 {
     $method = parent::fromReflection($reflectionMethod);
     /*
      * When overwriting methods PHP 7 enforces the same method parameters to be defined as in the base class. Since
      * the {@link \bitExpert\Disco\AnnotationBeanFactory} calls the generated methods without any parameters we
      * simply set a default value of null for each of the method parameters.
      */
     $method->setParameters([]);
     foreach ($reflectionMethod->getParameters() as $reflectionParameter) {
         $parameter = ParameterGenerator::fromReflection($reflectionParameter);
         $parameter->setDefaultValue(null);
         $method->setParameter($parameter);
     }
     return $method;
 }