本文整理匯總了PHP中Zend\Code\Generator\ParameterGenerator::generate方法的典型用法代碼示例。如果您正苦於以下問題:PHP ParameterGenerator::generate方法的具體用法?PHP ParameterGenerator::generate怎麽用?PHP ParameterGenerator::generate使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Zend\Code\Generator\ParameterGenerator
的用法示例。
在下文中一共展示了ParameterGenerator::generate方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: testGenerateIsCorrect
public function testGenerateIsCorrect()
{
$parameterGenerator = new ParameterGenerator();
$parameterGenerator->setType('Foo');
$parameterGenerator->setName('bar');
$parameterGenerator->setDefaultValue(15);
$this->assertEquals('Foo $bar = 15', $parameterGenerator->generate());
$parameterGenerator->setDefaultValue('foo');
$this->assertEquals('Foo $bar = \'foo\'', $parameterGenerator->generate());
}
示例2: getMethods
protected function getMethods()
{
$methods = [$this->getConstructor()];
foreach ($this->properties as $propertyName) {
$setterParam = new ParameterGenerator($propertyName);
$methodGenerator = new MethodGenerator('set' . ucfirst($propertyName), [$setterParam]);
$methodGenerator->setBody('$this->' . $propertyName . ' = ' . $setterParam->generate() . ';' . PHP_EOL . PHP_EOL . 'return $this;');
$methods[] = $methodGenerator;
$methodGenerator = new MethodGenerator('get' . ucfirst($propertyName));
$methodGenerator->setBody('return $this->' . $propertyName . ';');
$methods[] = $methodGenerator;
}
foreach ($this->edgeProperties as $edgeCollection => $targetCollection) {
$setterParam = new ParameterGenerator(lcfirst($edgeCollection));
$methodGenerator = new MethodGenerator('add' . $edgeCollection, [$setterParam]);
$methodGenerator->setBody('$this->lazyAddNeighbor($this, \'' . $edgeCollection . '\', ' . $setterParam->generate() . ');');
$methods[] = $methodGenerator;
$setterParam = new ParameterGenerator(lcfirst($edgeCollection));
$methodGenerator = new MethodGenerator('remove' . $edgeCollection, [$setterParam]);
$methodGenerator->setBody('$this->lazyRemoveNeighbor($this, \'' . $edgeCollection . '\', ' . $setterParam->generate() . ');');
$methods[] = $methodGenerator;
$setterParam = new ParameterGenerator(lcfirst($edgeCollection));
$methodGenerator = new MethodGenerator('set' . $edgeCollection, [$setterParam]);
$methodGenerator->setBody('$this->lazySetNeighbor($this, \'' . $edgeCollection . '\', ' . $setterParam->generate() . ');');
$methods[] = $methodGenerator;
$defaultValue = new ValueGenerator([], ValueGenerator::TYPE_ARRAY);
$setterParam = new ParameterGenerator('filter', null, $defaultValue);
$methodGenerator = new MethodGenerator('get' . $edgeCollection, [$setterParam]);
$methodGenerator->setBody('return $this->lazyGetNeighbor(\'' . $edgeCollection . '\', \'' . $targetCollection . '\', $filter);');
$methods[] = $methodGenerator;
}
return $methods;
}
示例3: testGeneratedParametersHaveEscapedDefaultValues
/**
* @group 6023
*
* @coversNothing
*/
public function testGeneratedParametersHaveEscapedDefaultValues()
{
$parameter = new ParameterGenerator();
$parameter->setName('foo');
$parameter->setDefaultValue("\\'");
$parameter->setType('stdClass');
$this->assertSame("stdClass \$foo = '\\\\\\''", $parameter->generate());
}