本文整理匯總了PHP中Zend\Code\Generator\MethodGenerator::getParameters方法的典型用法代碼示例。如果您正苦於以下問題:PHP MethodGenerator::getParameters方法的具體用法?PHP MethodGenerator::getParameters怎麽用?PHP MethodGenerator::getParameters使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Zend\Code\Generator\MethodGenerator
的用法示例。
在下文中一共展示了MethodGenerator::getParameters方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: testMethodParameterAccessors
public function testMethodParameterAccessors()
{
$methodGenerator = new MethodGenerator();
$methodGenerator->setParameters(array('one'));
$params = $methodGenerator->getParameters();
$param = array_shift($params);
$this->assertTrue($param instanceof \Zend\Code\Generator\ParameterGenerator, 'Failed because $param was not instance of Zend\\Code\\Generator\\ParameterGenerator');
}
示例2: buildClass
private function buildClass($replacement)
{
$type = $this->splitNsandClass($replacement['originalFullyQualifiedType']);
$class = new ClassGenerator();
$class->setName($type['class']);
$class->setNamespaceName($type['ns']);
$class->setExtendedClass('\\Brads\\Ppm\\Proxy');
$properties = [];
$methods = [];
$implementedInterfaces = [];
foreach ($versions as $version => $info) {
foreach ($info['files'] as $file) {
echo "Parsing: " . $this->vendorDir . '/' . $package . '/' . $version . '/' . $file . "\n";
$parsedFile = new ReflectionFile($this->vendorDir . '/' . $package . '/' . $version . '/' . $file);
$parsedClass = $parsedFile->getFileNamespace($info['toNs'])->getClass($info['toNs'] . '\\' . $type['class']);
if ($parsedClass->getInterfaceNames() != null) {
$implementedInterfaces = array_merge($implementedInterfaces, $parsedClass->getInterfaceNames());
}
foreach ($parsedClass->getMethods() as $method) {
if ($method->isPublic()) {
$generatedMethod = new MethodGenerator();
$generatedMethod->setName($method->name);
$generatedMethod->setBody('echo "Hello world!";');
$generatedMethod->setAbstract($method->isAbstract());
$generatedMethod->setFinal($method->isFinal());
$generatedMethod->setStatic($method->isStatic());
$generatedMethod->setVisibility(MethodGenerator::VISIBILITY_PUBLIC);
foreach ($method->getParameters() as $param) {
$generatedParam = new ParameterGenerator();
$generatedParam->setName($param->name);
if ($param->hasType()) {
$generatedParam->setType($param->getType());
}
//$generatedParam->setDefaultValue($param->getDefaultValue());
$generatedParam->setPosition($param->getPosition());
$generatedParam->setVariadic($param->isVariadic());
$generatedParam->setPassedByReference($param->isPassedByReference());
$generatedMethod->setParameter($generatedParam);
}
$existingMethod = Linq::from($methods)->firstOrDefault(null, function (MethodGenerator $v) use($method) {
return $v->getName() == $method->name;
});
if ($existingMethod != null) {
$existingParams = $existingMethod->getParameters();
foreach ($generatedMethod->getParameters() as $newParam) {
$existingParam = Linq::from($existingParams)->firstOrDefault(function (ParameterGenerator $v) {
return $v->getName() == $newParam->getName();
});
if ($existingParam == null) {
$existingMethod->setParameter($newParam);
}
}
} else {
$methods[] = $generatedMethod;
}
}
}
foreach ($parsedClass->getProperties() as $prop) {
//$properties[] = PropertyGenerator::fromReflection($prop);
}
}
}
$class->setImplementedInterfaces($implementedInterfaces);
$class->addMethods($methods);
$class->addProperties($properties);
return (new FileGenerator(['classes' => [$class]]))->generate();
}