/** * @param $name * @param $visibility * @param $default * @param $type * * @return PropertyGenerator */ public static function property($name, $visibility = 'public', $default = null, $type = 'mixed') { $property = (new PropertyGenerator($name, $default))->setVisibility($visibility); $property->setIndentation(Generator::$indentation); $docBlock = new DocBlockGenerator(); $docBlock->setIndentation(Generator::$indentation); $tag = new Tag(); $tag->setName('var'); $tag->setContent($type); $tag->setIndentation(Generator::$indentation); $docBlock->setTag($tag); $property->setDocBlock($docBlock); return $property; }
/** * @param array $options */ public function __construct(array $options = array()) { parent::__construct($options); if (isset($options['url'])) { $this->setUrl($options['url']); } if (empty($this->name)) { $this->setName('license'); } }
/** * fromReflection() - Build a docblock generator object from a reflection object * * @param ReflectionDocblock $reflectionDocblock * @return DocblockGenerator */ public static function fromReflection(DocBlockReflection $reflectionDocblock) { $docblock = new self(); $docblock->setSourceContent($reflectionDocblock->getContents()); $docblock->setSourceDirty(false); $docblock->setShortDescription($reflectionDocblock->getShortDescription()); $docblock->setLongDescription($reflectionDocblock->getLongDescription()); foreach ($reflectionDocblock->getTags() as $tag) { $docblock->setTag(Docblock\Tag::fromReflection($tag)); } return $docblock; }
public function testParamProducesCorrectDocBlockTag() { $this->tag->setName('foo'); $this->tag->setDescription('bar bar bar'); $this->assertEquals('@foo bar bar bar', $this->tag->generate()); }
private function getServiceCode() { $code = new ClassGenerator($this->service->getName(), $this->namespace, null, '\\SoapClient'); $doc = $this->service->getDoc(); if ($doc) { $docBlock = new DocBlockGenerator($doc); $code->setDocBlock($docBlock); } foreach ($this->service->getFunctions() as $function) { $method = new MethodGenerator($function->getMethod()); $docBlock = new DocBlockGenerator($function->getDoc()); foreach ($function->getParams() as $param) { $methodParam = new ParameterGenerator($param->getName()); if (false === $param->isPrimitive()) { $methodParam->setType('\\' . $this->getFullNamespace($param->getType())); } $method->setParameter($methodParam); $tag = new Tag(); $tag->setName('property'); $type = $param->getType(); if (false === $param->isPrimitive()) { $type = '\\' . $this->getFullNamespace($param->getType()); } $tag->setDescription(sprintf('%s $%s', $type, $param->getName())); $docBlock->setTag($tag); } $tag = new Tag(); $tag->setName('returns'); $tag->setDescription("\\" . $this->getFullNamespace($function->getReturns())); $docBlock->setTag($tag); $method->setBody(sprintf('return $this->__soapCall("%s", func_get_args());', $function->getName())); $method->setDocBlock($docBlock); $code->addMethodFromGenerator($method); } return $code; }
protected function generateDocblock($requestTypeName, $requestType, $returnType) { $docblock = $this->getDocblockGenerator(); $scalarTypes = $this->getScalarTypes(); $isScalarReturn = false; if (isset($scalarTypes[$returnType])) { $returnType = $scalarTypes[$returnType]; $isScalarReturn = true; } if ($requestNamespace = $this->getRequestNamespace()) { $requestType = Soap::REQUEST_NAMESPACE_ALIAS . '\\' . $requestType; if (!$isScalarReturn) { $returnType = Soap::RESPONSE_NAMESPACE_ALIAS . '\\' . $returnType; } } $apiTag = new CodeGenerator\DocBlock\Tag(); $apiTag->setName('api'); $docblock->setTag($apiTag); $parameterTag = new CodeGenerator\DocBlock\Tag\ParamTag(); $parameterTag->setDataType($requestType); $parameterTag->setParamName(lcfirst($requestTypeName)); $docblock->setTag($parameterTag); $returnTag = new CodeGenerator\DocBlock\Tag\ReturnTag(); $returnTag->setDataType($returnType); $docblock->setTag($returnTag); return $docblock; }
public function testDescriptionGetterAndSetterPersistValue() { $this->_tag->setDescription('Foo foo foo'); $this->assertEquals('Foo foo foo', $this->_tag->getDescription()); }
public function getDocBlockGenerator() { if (!$this->docBlockGenerator) { $generator = new CodeGenerator\DocBlockGenerator(); $apiTag = new CodeGenerator\DocBlock\Tag(); $apiTag->setName('api'); $generator->setTag($apiTag); $this->docBlockGenerator = $generator; } return $this->docBlockGenerator; }
/** * @param array|TagInterface $tag * @throws Exception\InvalidArgumentException * @return DocBlockGenerator */ public function setTag($tag) { if (is_array($tag)) { // use deprecated Tag class for backward compatiblity to old array-keys $genericTag = new Tag(); $genericTag->setOptions($tag); $tag = $genericTag; } elseif (!$tag instanceof TagInterface) { throw new Exception\InvalidArgumentException(sprintf('%s expects either an array of method options or an instance of %s\\DocBlock\\Tag\\TagInterface', __METHOD__, __NAMESPACE__)); } $this->tags[] = $tag; return $this; }
protected function handleSetter(Generator\ClassGenerator $generator, PHPProperty $prop, PHPClass $class) { $name = "set" . Inflector::classify($prop->getName()); $type = $this->getPropertyType($prop); $namespace = explode("\\", $type); $namespaceClass = array_pop($namespace); $namespace = implode("\\", $namespace); if ($namespace == $class->getNamespace() || $namespace == "\\" . $class->getNamespace()) { $type = $namespaceClass; } if (substr($type, -2) == "[]") { $type = "array"; } $fullName = "method {$class->getName()} {$name}({$type} \${$prop->getName()})"; $docblock = $generator->getDocBlock(); $docblock->setWordWrap(false); $tag = new Generator\DocBlock\Tag(); $tag->setName($fullName); $docblock->setTag($tag); return; }
protected function handleSecondClassElements(CodeGenerator\ClassGenerator $classGenerator, array &$map, DOMNodeList $secondClassElements, DOMNode $element, DOMXPath $xpath) { foreach ($secondClassElements as $secondClassElement) { $maxOccursNode = $xpath->query('@maxOccurs', $secondClassElement)->item(0); $maxOccurs = $maxOccursNode ? $maxOccursNode->textContent : null; $unbounded = $maxOccurs == 'unbounded'; $hydrationModifier = '#'; $secondClassElementName = null; $secondClassElementNameNode = $xpath->query('@name', $secondClassElement)->item(0); if ($secondClassElementNameNode) { $secondClassElementName = $secondClassElementNameNode->textContent; $this->generateResource($secondClassElement); } else { $secondClassElementNameNode = $xpath->query('@ref', $secondClassElement)->item(0); if ($secondClassElementNameNode) { if (substr($secondClassElementNameNode->textContent, 0, 4) == "tns:") { $secondClassElementName = substr($secondClassElementNameNode->textContent, 4); } elseif (substr($secondClassElementNameNode->textContent, 0, 5) == "data:") { $secondClassElementName = substr($secondClassElementNameNode->textContent, 5); } } } if (!$secondClassElementName) { continue; } $secondClassElementType = $secondClassElementName; if ($unbounded) { $secondClassElementType .= "[]"; } $propertyName = lcfirst($secondClassElementName); if ($unbounded) { $propertyName .= 's'; } $secondClassElementProperty = clone $this->getPropertyGenerator(); $secondClassElementProperty->setName($propertyName); if ($unbounded) { $secondClassElementProperty->setDefaultValue(new CodeGenerator\PropertyValueGenerator(array())); $hydrationModifier .= '@'; $mapKeyName = "{$secondClassElementName}s"; } else { $mapKeyName = $secondClassElementName; } if ($secondClassElementType) { $secondClassElementPropertyDocblock = clone $this->getPropertyDocblockGenerator(); $secondClassElementProperty->setDocBlock($secondClassElementPropertyDocblock); $typeTag = new CodeGenerator\DocBlock\Tag(); $typeTag->setName('var'); $typeTag->setDescription($secondClassElementType); $secondClassElementPropertyDocblock->setTag($typeTag); } $classGenerator->addPropertyFromGenerator($secondClassElementProperty); $getterGenerator = $this->generatePropertyGetter($propertyName); $setterGenerator = $this->generatePropertySetter($propertyName); $classGenerator->addMethods(array($getterGenerator, $setterGenerator)); $map["{$hydrationModifier}{$mapKeyName}"] = "_:{$secondClassElementName}"; } }