本文整理汇总了PHP中Zend\Code\Generator\ParameterGenerator::fromReflection方法的典型用法代码示例。如果您正苦于以下问题:PHP ParameterGenerator::fromReflection方法的具体用法?PHP ParameterGenerator::fromReflection怎么用?PHP ParameterGenerator::fromReflection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\Code\Generator\ParameterGenerator
的用法示例。
在下文中一共展示了ParameterGenerator::fromReflection方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: fromReflection
/**
* @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: fromReflection
/**
* 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: testFromReflectionGenerate
/**
* @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());
}
示例4: testFromReflectionGenerate
/**
* @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: testTypehintsWithNamespaceInNamepsacedClassReturnTypewithBackslash
/**
* @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: fromReflection
/**
* @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;
}