本文整理汇总了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());
}