本文整理汇总了PHP中Zend\Code\Generator\ParameterGenerator::setName方法的典型用法代码示例。如果您正苦于以下问题:PHP ParameterGenerator::setName方法的具体用法?PHP ParameterGenerator::setName怎么用?PHP ParameterGenerator::setName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\Code\Generator\ParameterGenerator
的用法示例。
在下文中一共展示了ParameterGenerator::setName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: generate
public function generate()
{
$modelBuilder = $this->controller->getModelBuilder();
$className = $modelBuilder->getName() . 'Controller';
$class = new ClassGenerator();
$class->setName($className);
$class->setExtendedClass('CrudController');
$param = new ParameterGenerator();
$param->setName('fb')->setType('FormBuilder');
$body = $this->generateFormBuilderBody();
$docblock = '@param FormBuilder $fb';
$class->addMethod('buildForm', array($param), MethodGenerator::FLAG_PUBLIC, $body, $docblock);
$param = new ParameterGenerator();
$param->setName('mb')->setType('ModelBuilder');
$body = '';
$docblock = '@param ModelBuilder $mb';
$class->addMethod('buildModel', array($param), MethodGenerator::FLAG_PUBLIC, $body, $docblock);
$param = new ParameterGenerator();
$param->setName('ob')->setType('OverviewBuilder');
$body = '';
$docblock = '@param OverviewBuilder $ob';
$class->addMethod('buildOverview', array($param), MethodGenerator::FLAG_PUBLIC, $body, $docblock);
$this->generator->setClass($class);
$this->generator->setUses(array('Boyhagemann\\Crud\\CrudController', 'Boyhagemann\\Form\\FormBuilder', 'Boyhagemann\\Model\\ModelBuilder', 'Boyhagemann\\Overview\\OverviewBuilder'));
return $this->generator->generate();
}
示例2: generate
public function generate()
{
if ($this->controller) {
$modelBuilder = $this->controller->getModelBuilder();
$className = $modelBuilder->getName();
} else {
$className = $this->class;
}
$modelClass = $this->modelClass ? $this->modelClass : $this->class;
$class = new ClassGenerator();
$class->setName($className);
$class->setExtendedClass('CrudController');
$class->addUse('Boyhagemann\\Crud\\CrudController');
$class->addUse('Boyhagemann\\Form\\FormBuilder');
$class->addUse('Boyhagemann\\Model\\ModelBuilder');
$class->addUse('Boyhagemann\\Overview\\OverviewBuilder');
$param = new ParameterGenerator();
$param->setName('fb')->setType('FormBuilder');
$body = $this->generateFormBuilderBody();
$docblock = '@param FormBuilder $fb';
$class->addMethod('buildForm', array($param), MethodGenerator::FLAG_PUBLIC, $body, $docblock);
$param = new ParameterGenerator();
$param->setName('mb')->setType('ModelBuilder');
$body = sprintf('$mb->name(\'%s\')->table(\'%s\');' . PHP_EOL, $modelClass, strtolower(str_replace('\\', '_', $modelClass)));
$docblock = '@param ModelBuilder $mb';
$class->addMethod('buildModel', array($param), MethodGenerator::FLAG_PUBLIC, $body, $docblock);
$param = new ParameterGenerator();
$param->setName('ob')->setType('OverviewBuilder');
$body = '';
$docblock = '@param OverviewBuilder $ob';
$class->addMethod('buildOverview', array($param), MethodGenerator::FLAG_PUBLIC, $body, $docblock);
$this->generator->setClass($class);
return $this->generator->generate();
}
示例3: fromReflection
/**
* @param ParameterReflection $reflectionParameter
* @return ParameterGenerator
*/
public static function fromReflection(ParameterReflection $reflectionParameter)
{
$param = new ParameterGenerator();
$param->setName($reflectionParameter->getName());
if ($reflectionParameter->isArray()) {
$param->setType('array');
} elseif (method_exists($reflectionParameter, 'isCallable') && $reflectionParameter->isCallable()) {
$param->setType('callable');
} else {
$typeClass = $reflectionParameter->getClass();
if ($typeClass) {
$parameterType = $typeClass->getName();
$currentNamespace = $reflectionParameter->getDeclaringClass()->getNamespaceName();
if (!empty($currentNamespace) && substr($parameterType, 0, strlen($currentNamespace)) == $currentNamespace) {
$parameterType = substr($parameterType, strlen($currentNamespace) + 1);
} else {
$parameterType = '\\' . trim($parameterType, '\\');
}
$param->setType($parameterType);
}
}
$param->setPosition($reflectionParameter->getPosition());
if ($reflectionParameter->isOptional()) {
$param->setDefaultValue($reflectionParameter->getDefaultValue());
}
$param->setPassedByReference($reflectionParameter->isPassedByReference());
return $param;
}
示例4: fromReflection
/**
* @param ParameterReflection $reflectionParameter
* @return ParameterGenerator
*/
public static function fromReflection(ParameterReflection $reflectionParameter)
{
$param = new ParameterGenerator();
$param->setName($reflectionParameter->getName());
if ($reflectionParameter->isArray()) {
$param->setType('array');
} elseif (method_exists($reflectionParameter, 'isCallable') && $reflectionParameter->isCallable()) {
$param->setType('callable');
} else {
$typeClass = $reflectionParameter->getClass();
if ($typeClass) {
$param->setType($typeClass->getName());
}
}
$param->setPosition($reflectionParameter->getPosition());
if ($reflectionParameter->isOptional()) {
$param->setDefaultValue($reflectionParameter->getDefaultValue());
}
$param->setPassedByReference($reflectionParameter->isPassedByReference());
return $param;
}
示例5: 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());
}
示例6: generatePropertyAdder
public function generatePropertyAdder($propertyName)
{
$parameterName = rtrim($propertyName, 's');
$methodName = 'add' . ucfirst($parameterName);
$setterGenerator = clone $this->getPropertySetterGenerator();
$setterGenerator->setName($methodName);
$parameter = new CodeGenerator\ParameterGenerator();
$parameter->setName($parameterName);
$setterGenerator->setParameter($parameter);
$valueParameter = new CodeGenerator\ParameterGenerator();
$valueParameter->setName('value');
$setterGenerator->setParameter($valueParameter);
$setterGenerator->setBody("\$this->{$propertyName}[\${$parameterName}] = \$value;\nreturn \$this;");
return $setterGenerator;
}
示例7: fromReflection
/**
* @param ParameterReflection $reflectionParameter
* @return ParameterGenerator
*/
public static function fromReflection(ParameterReflection $reflectionParameter)
{
$param = new ParameterGenerator();
$param->setName($reflectionParameter->getName());
if ($type = self::extractFQCNTypeFromReflectionType($reflectionParameter)) {
$param->setType($type);
}
$param->setPosition($reflectionParameter->getPosition());
$variadic = method_exists($reflectionParameter, 'isVariadic') && $reflectionParameter->isVariadic();
$param->setVariadic($variadic);
if (!$variadic && $reflectionParameter->isOptional()) {
try {
$param->setDefaultValue($reflectionParameter->getDefaultValue());
} catch (\ReflectionException $e) {
$param->setDefaultValue(null);
}
}
$param->setPassedByReference($reflectionParameter->isPassedByReference());
return $param;
}
示例8: transform
public function transform()
{
$classGenerator = $this->getService()->getClassGenerator();
if ($createContactBatch = $classGenerator->getMethod('CreateContactBatch')) {
$newMethod = new CodeGenerator\MethodGenerator();
$newMethod->setName($createContactBatch->getName());
$docblock = $createContactBatch->getDocBlock();
$docblock->setTag((new CodeGenerator\DocBlock\Tag\ParamTag())->setParamName('id')->setDataType('int'));
$newMethod->setDocBlock($docblock);
$parameters = $createContactBatch->getParameters();
$idParameter = new CodeGenerator\ParameterGenerator();
$idParameter->setName('id');
$createContactBatch->setParameter($idParameter);
$newMethod->setParameters(array("id" => $idParameter, "CreateContactBatch" => $parameters['CreateContactBatch']));
$body = $createContactBatch->getBody();
$body = str_replace('array()', 'array($id)', $body);
$newMethod->setBody($body);
$classGenerator->removeMethod('CreateContactBatch');
$classGenerator->addMethodFromGenerator($newMethod);
}
}
示例9: generatePropertyAdder
public function generatePropertyAdder($propertyName, $withIndex = true, $proxyPropertyName = null)
{
$proxyPropertyName = $proxyPropertyName ?: $propertyName;
list($parameterName, $methodName) = $this->generatePropertyAdderName($proxyPropertyName);
$setterGenerator = clone $this->getPropertySetterGenerator();
$setterGenerator->setName($methodName);
if ($withIndex) {
$parameter = new CodeGenerator\ParameterGenerator();
$parameter->setName($parameterName);
$setterGenerator->setParameter($parameter);
}
$valueParameter = new CodeGenerator\ParameterGenerator();
$valueParameter->setName('value');
$setterGenerator->setParameter($valueParameter);
if ($withIndex) {
$setterGenerator->setBody("\$this->{$propertyName}[\${$parameterName}] = \$value;\nreturn \$this;");
} else {
$setterGenerator->setBody("\$this->{$propertyName}[] = \$value;\nreturn \$this;");
}
return $setterGenerator;
}
示例10: generatePropertySetter
public function generatePropertySetter($property)
{
$property = lcfirst($property);
$methodName = 'set' . ucfirst($property);
$setterGenerator = clone $this->getPropertySetterGenerator();
$setterGenerator->setName($methodName);
$parameter = new CodeGenerator\ParameterGenerator();
$parameter->setName($property);
$setterGenerator->setParameter($parameter);
$setterGenerator->setBody("\$this->{$property} = \${$property};\nreturn \$this;");
return $setterGenerator;
}
示例11: getCodeGenerator
//.........这里部分代码省略.........
continue;
}
$methodName = isset($methodData['name']) ? $methodData['name'] : $methodData['method'];
$methodParams = $methodData['params'];
// Create method parameter representation
foreach ($methodParams as $key => $param) {
if (null === $param || is_scalar($param) || is_array($param)) {
$string = var_export($param, 1);
if (strstr($string, '::__set_state(')) {
throw new Exception\RuntimeException('Arguments in definitions may not contain objects');
}
$methodParams[$key] = $string;
} elseif ($param instanceof GeneratorInstance) {
$methodParams[$key] = sprintf('$this->%s()', $this->normalizeAlias($param->getName()));
} else {
$message = sprintf('Unable to use object arguments when generating method calls. Encountered with class "%s", method "%s", parameter of type "%s"', $name, $methodName, get_class($param));
throw new Exception\RuntimeException($message);
}
}
// Strip null arguments from the end of the params list
$reverseParams = array_reverse($methodParams, true);
foreach ($reverseParams as $key => $param) {
if ('NULL' === $param) {
unset($methodParams[$key]);
continue;
}
break;
}
$methods .= sprintf("\$object->%s(%s);\n", $methodName, implode(', ', $methodParams));
}
// Generate caching statement
$storage = '';
if ($im->hasSharedInstance($name, $params)) {
$storage = sprintf("\$this->services['%s'] = \$object;\n", $name);
}
// Start creating getter
$getterBody = '';
// Create fetch of stored service
if ($im->hasSharedInstance($name, $params)) {
$getterBody .= sprintf("if (isset(\$this->services['%s'])) {\n", $name);
$getterBody .= sprintf("%sreturn \$this->services['%s'];\n}\n\n", $indent, $name);
}
// Creation and method calls
$getterBody .= sprintf("%s\n", $creation);
$getterBody .= $methods;
// Stored service
$getterBody .= $storage;
// End getter body
$getterBody .= "return \$object;\n";
$getterDef = new MethodGenerator();
$getterDef->setName($getter);
$getterDef->setBody($getterBody);
$getters[] = $getterDef;
// Get cases for case statements
$cases = array($name);
if (isset($aliases[$name])) {
$cases = array_merge($aliases[$name], $cases);
}
// Build case statement and store
$statement = '';
foreach ($cases as $value) {
$statement .= sprintf("%scase '%s':\n", $indent, $value);
}
$statement .= sprintf("%sreturn \$this->%s();\n", str_repeat($indent, 2), $getter);
$caseStatements[] = $statement;
}
// Build switch statement
$switch = sprintf("switch (%s) {\n%s\n", '$name', implode("\n", $caseStatements));
$switch .= sprintf("%sdefault:\n%sreturn parent::get(%s, %s);\n", $indent, str_repeat($indent, 2), '$name', '$params');
$switch .= "}\n\n";
// Build get() method
$nameParam = new ParameterGenerator();
$nameParam->setName('name');
$paramsParam = new ParameterGenerator();
$paramsParam->setName('params')->setType('array')->setDefaultValue(array());
$get = new MethodGenerator();
$get->setName('get');
$get->setParameters(array($nameParam, $paramsParam));
$get->setBody($switch);
// Create getters for aliases
$aliasMethods = array();
foreach ($aliases as $class => $classAliases) {
foreach ($classAliases as $alias) {
$aliasMethods[] = $this->getCodeGenMethodFromAlias($alias, $class);
}
}
// Create class code generation object
$container = new ClassGenerator();
$container->setName($this->containerClass)->setExtendedClass('ServiceLocator')->addMethodFromGenerator($get)->addMethods($getters)->addMethods($aliasMethods);
// Create PHP file code generation object
$classFile = new FileGenerator();
$classFile->setUse('Zend\\Di\\ServiceLocator')->setClass($container);
if (null !== $this->namespace) {
$classFile->setNamespace($this->namespace);
}
if (null !== $filename) {
$classFile->setFilename($filename);
}
return $classFile;
}
示例12: 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();
}
示例13: generateParameterSetter
public function generateParameterSetter($parameterName, $swaggerParameter)
{
$methodName = 'set' . ucfirst($parameterName);
$setterGenerator = clone $this->getParameterSetterGenerator();
$setterGenerator->setName($methodName);
$parameter = new CodeGenerator\ParameterGenerator();
$parameter->setName($parameterName);
$setterGenerator->setParameter($parameter);
$setterGenerator->setBody("\$this->{$parameterName} = \${$parameterName};\nreturn \$this;");
return $setterGenerator;
}
示例14: generateMethod
/**
* Generate method
*
* @param string $methodName
* @return void
*/
protected function generateMethod($methodName)
{
$methodReflection = $this->_method[$methodName];
$docBlock = new DocBlockGenerator();
$docBlock->setShortDescription("Delicate {$methodName}() to __call() method ");
if ($methodReflection->getDocComment()) {
$docBlockReflection = new DocBlockReflection($methodReflection);
$docBlock->fromReflection($docBlockReflection);
}
$method = new MethodGenerator();
$method->setName($methodName);
$method->setDocBlock($docBlock);
$method->setBody(sprintf(self::METHOD_TEMPLATE, $methodName));
if ($methodReflection->isPublic()) {
$method->setVisibility(MethodGenerator::VISIBILITY_PUBLIC);
} else {
if ($methodReflection->isProtected()) {
$method->setVisibility(MethodGenerator::VISIBILITY_PROTECTED);
} else {
if ($methodReflection->isPrivate()) {
$method->setVisibility(MethodGenerator::VISIBILITY_PRIVATE);
}
}
}
foreach ($methodReflection->getParameters() as $parameter) {
$parameterGenerator = new ParameterGenerator();
$parameterGenerator->setPosition($parameter->getPosition());
$parameterGenerator->setName($parameter->getName());
$parameterGenerator->setPassedByReference($parameter->isPassedByReference());
if ($parameter->isDefaultValueAvailable()) {
$parameterGenerator->setDefaultValue($parameter->getDefaultValue());
}
if ($parameter->isArray()) {
$parameterGenerator->setType('array');
}
if ($typeClass = $parameter->getClass()) {
$parameterGenerator->setType($typeClass->getName());
}
$method->setParameter($parameterGenerator);
}
$this->addMethodFromGenerator($method);
}
示例15: getConstructorGenerator
public function getConstructorGenerator()
{
if (!$this->constructorGenerator && ($extendedClass = $this->getClassGenerator()->getExtendedClass())) {
$constructorGenerator = new CodeGenerator\MethodGenerator();
$constructorGenerator->setName('__construct');
$wsdlParameter = new CodeGenerator\ParameterGenerator();
$wsdlParameter->setName('wsdl');
$wsdlParameter->setDefaultValue($this->getWsdl());
$constructorGenerator->setParameter($wsdlParameter);
$optionsParameter = new CodeGenerator\ParameterGenerator();
$optionsParameter->setName('options');
$optionsParameter->setDefaultValue(array());
$constructorGenerator->setParameter($optionsParameter);
$constructorGenerator->setBody("parent::__construct(\$wsdl, \$options);");
$this->constructorGenerator = $constructorGenerator;
}
return $this->constructorGenerator;
}