本文整理汇总了PHP中Zend\Code\Generator\PropertyGenerator::setName方法的典型用法代码示例。如果您正苦于以下问题:PHP PropertyGenerator::setName方法的具体用法?PHP PropertyGenerator::setName怎么用?PHP PropertyGenerator::setName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\Code\Generator\PropertyGenerator
的用法示例。
在下文中一共展示了PropertyGenerator::setName方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: addProperty
/**
* @param type $name
* @param type $type
* @param type $docString
* @return PhpProperty
*/
public function addProperty($name, $type, $docString)
{
$property = new PropertyGenerator();
$docblock = new DocBlockGenerator();
$property->setName($name);
$property->setVisibility(PropertyGenerator::VISIBILITY_PROTECTED);
$docblock->setShortDescription($docString);
$docblock->setTag(new Tag(array('name' => 'var', 'description' => $type)));
$property->setDocblock($docblock);
$this->addPropertyFromGenerator($property);
return $property;
}
示例2: generate
public function generate()
{
$classGenerator = $this->getClassGenerator();
$description = $this->getDescription();
$classGenerator->setName($description->getName());
$basePathProperty = new CodeGenerator\PropertyGenerator();
$basePathProperty->setName('basePath');
$basePathProperty->setDefaultValue($description->getBasePath());
$classGenerator->addPropertyFromGenerator($basePathProperty);
foreach ($description->getApis() as $api) {
foreach ($api->getOperations() as $operation) {
$function = $this->generateFunction($api, $operation);
if ($function instanceof CodeGenerator\MethodGenerator) {
$classGenerator->addMethodFromGenerator($function);
}
}
}
}
示例3: generateProperty
protected function generateProperty($type, $name)
{
$property = new CodeGenerator\PropertyGenerator();
$property->setName(lcfirst($name));
$property->setVisibility($property::VISIBILITY_PROTECTED);
return $property;
}
示例4: getTypesCode
/**
* @return ClassGenerator[]
*/
private function getTypesCode()
{
$generator = $this;
return array_map(function (Structure\TypeStructure $type) use($generator) {
$code = new ClassGenerator($type->getClassName());
$code->setNamespaceName($generator->getFullNamespace($type->getClassName(), true));
foreach ($type->getMembers() as $member) {
$tag = new Tag();
$tag->setName('var');
if ($member->isPrimitive()) {
$tag->setDescription($member->getType());
} else {
$tag->setDescription("\\" . $generator->getFullNamespace($member->getType()));
}
$docBlock = new DocBlockGenerator(null, null, [$tag]);
$property = new PropertyGenerator();
$property->setName($member->getName());
$property->setDocBlock($docBlock);
$code->addPropertyFromGenerator($property);
}
return $code;
}, $this->service->getTypes()->getArrayCopy());
}
示例5: addMessageTemplates
/**
* @param $className
*/
protected function addMessageTemplates($className)
{
// generate property
$property = new PropertyGenerator();
$property->setName('messageTemplates');
$property->setDefaultValue(['invalid' . $className => 'Value "%value%" is not valid']);
$property->setVisibility(PropertyGenerator::FLAG_PROTECTED);
// check for api docs
if ($this->config['flagAddDocBlocks']) {
$property->setDocBlock(new DocBlockGenerator('Validation failure message template definitions', '', [new GenericTag('var', 'array')]));
}
// add property
$this->addPropertyFromGenerator($property);
}
示例6: testHasProperty
/**
* @group ZF-7361
*/
public function testHasProperty()
{
$property = new PropertyGenerator();
$property->setName('propertyOne');
$classGenerator = new ClassGenerator();
$classGenerator->setProperty($property);
$this->assertTrue($classGenerator->hasProperty('propertyOne'));
}
示例7: createProperty
/**
* Create a property instance
* @param string $name - property name
* @return Generator\PropertyGenerator $property
*/
private function createProperty($name)
{
$property = new Generator\PropertyGenerator();
$property->setName($name);
$property->setVisibility(Generator\AbstractMemberGenerator::FLAG_PUBLIC);
return $property;
}
示例8: createDTO
/**
* {@inheritdoc}
*/
public function createDTO(Type $type)
{
$class = $this->createClassFromType($type);
$parentType = $type->getParent();
// set the parent class
if ($parentType) {
$parentType = $parentType->getBase();
if ($parentType->getSchema()->getTargetNamespace() !== SchemaReader::XSD_NS) {
$class->setExtendedClass($parentType->getName());
}
}
// check if the type is abstract
$class->setAbstract($type->isAbstract());
// create the constructor
$constructor = new MethodGenerator('__construct');
$constructorDoc = new DocBlockGenerator();
$constructorBody = '';
$constructor->setDocBlock($constructorDoc);
$class->addMethodFromGenerator($constructor);
/* @var \Goetas\XML\XSDReader\Schema\Type\ComplexType $type */
foreach ($type->getElements() as $element) {
/* @var \Goetas\XML\XSDReader\Schema\Element\Element $element */
$docElementType = $this->namespaceInflector->inflectDocBlockQualifiedName($element->getType());
$elementName = $element->getName();
// create a param and a param tag used in constructor and setter docs
$param = new ParameterGenerator($elementName, $this->namespaceInflector->inflectName($element->getType()));
$paramTag = new ParamTag($elementName, $docElementType);
// if the param type is not a PHP primitive type and its namespace is different that the class namespace
if ($type->getSchema()->getTargetNamespace() === SchemaReader::XSD_NS and $class->getNamespaceName() !== $this->namespaceInflector->inflectNamespace($element->getType())) {
$class->addUse($this->namespaceInflector->inflectQualifiedName($element->getType()));
}
// set the parameter nullability
if ($element->isNil() or $this->config->isNullConstructorArguments()) {
$param->setDefaultValue(new ValueGenerator(null, ValueGenerator::TYPE_NULL));
}
/*
* PROPERTY CREATION
*/
$docDescription = new Html2Text($type->getDoc());
$doc = new DocBlockGenerator();
$doc->setShortDescription($docDescription->getText());
$doc->setTag(new GenericTag('var', $docElementType));
$property = new PropertyGenerator();
$property->setDocBlock($doc);
$property->setName(filter_var($elementName, FILTER_CALLBACK, array('options' => array($this, 'sanitizeVariableName'))));
$property->setVisibility($this->config->isAccessors() ? AbstractMemberGenerator::VISIBILITY_PROTECTED : AbstractMemberGenerator::VISIBILITY_PUBLIC);
$class->addPropertyFromGenerator($property);
/*
* IMPORTS
*/
if ($element->getType()->getSchema()->getTargetNamespace() !== SchemaReader::XSD_NS and $this->namespaceInflector->inflectNamespace($element->getType()) !== $class->getNamespaceName()) {
$class->addUse($this->namespaceInflector->inflectQualifiedName($element->getType()));
}
/*
* CONSTRUCTOR PARAM CREATION
*/
$constructorDoc->setTag($paramTag);
$constructorBody .= "\$this->{$elementName} = \${$elementName};" . AbstractGenerator::LINE_FEED;
$constructor->setParameter($param);
/*
* ACCESSORS CREATION
*/
if ($this->config->isAccessors()) {
// create the setter
$setterDoc = new DocBlockGenerator();
$setterDoc->setTag($paramTag);
$setter = new MethodGenerator('set' . ucfirst($elementName));
$setter->setParameter($param);
$setter->setDocBlock($setterDoc);
$setter->setBody("\$this->{$elementName} = \${$elementName};");
$class->addMethodFromGenerator($setter);
// create the getter
$getterDoc = new DocBlockGenerator();
$getterDoc->setTag(new ReturnTag($docElementType));
$getter = new MethodGenerator('get' . ucfirst($elementName));
$getter->setDocBlock($getterDoc);
$getter->setBody("return \$this->{$elementName};");
$class->addMethodFromGenerator($getter);
}
}
// finalize the constructor body
$constructor->setBody($constructorBody);
$this->serializeClass($class);
// register the class in the classmap
$this->classmap[$class->getName()] = $class->getNamespaceName() . '\\' . $class->getName();
return $class->getName();
}
示例9: generateProxiesMapProp
private function generateProxiesMapProp()
{
$map = new PropertyGenerator();
$map->setName('proxiesMap');
$map->setVisibility(PropertyGenerator::VISIBILITY_PROTECTED);
$map->setDefaultValue($this->buildProxiesMap(), 'array');
return $map;
}