/** * @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; }
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); } } } }
protected function generateProperty($type, $name) { $property = new CodeGenerator\PropertyGenerator(); $property->setName(lcfirst($name)); $property->setVisibility($property::VISIBILITY_PROTECTED); return $property; }
/** * @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()); }
/** * @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); }
/** * @group ZF-7361 */ public function testHasProperty() { $property = new PropertyGenerator(); $property->setName('propertyOne'); $classGenerator = new ClassGenerator(); $classGenerator->setProperty($property); $this->assertTrue($classGenerator->hasProperty('propertyOne')); }
/** * 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; }
/** * {@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(); }
private function generateProxiesMapProp() { $map = new PropertyGenerator(); $map->setName('proxiesMap'); $map->setVisibility(PropertyGenerator::VISIBILITY_PROTECTED); $map->setDefaultValue($this->buildProxiesMap(), 'array'); return $map; }