本文整理汇总了PHP中phpDocumentor\Reflection\DocBlock::getTagsByName方法的典型用法代码示例。如果您正苦于以下问题:PHP DocBlock::getTagsByName方法的具体用法?PHP DocBlock::getTagsByName怎么用?PHP DocBlock::getTagsByName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类phpDocumentor\Reflection\DocBlock
的用法示例。
在下文中一共展示了DocBlock::getTagsByName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getMethodsDetails
public function getMethodsDetails()
{
$methods = [];
foreach ($this->reflection->getMethods(ReflectionMethod::IS_PUBLIC) as $method) {
$docblock = new DocBlock($method);
$data = ['shortDescription' => $docblock->getShortDescription(), 'longDescription' => $docblock->getLongDescription(), 'argumentsList' => $this->retriveParams($docblock->getTagsByName('param')), 'argumentsDescription' => $this->retriveParamsDescription($docblock->getTagsByName('param')), 'returnValue' => $this->retriveReturnValue($docblock->getTagsByName('return')), 'visibility' => join('', [$method->isFinal() ? 'final ' : '', 'public', $method->isStatic() ? ' static' : ''])];
if (strlen($data['shortDescription'])) {
$methods[$method->getName()] = (object) $data;
}
}
return $methods;
}
示例2: resolveSignature
public function resolveSignature($comment)
{
$docblock = new DocBlock((string) $comment);
$return = $docblock->getTagsByName("return");
if (count($return) !== 1) {
$returnType = new Type(Type::TYPE_UNKNOWN);
} else {
$returnType = Type::normalizeType($return[0]->getType());
}
$params = $docblock->getTagsByName("param");
$paramTypes = [];
foreach ($params as $key => $param) {
$paramTypes[] = Type::normalizeType($params[$key]->getType());
}
return new Signature($returnType, $paramTypes);
}
示例3: configure
protected function configure()
{
$reflection = new \ReflectionClass(get_called_class());
$baseNamespaceChunks = [];
foreach (explode('\\', $reflection->getNamespaceName()) as $namespaceChunk) {
$baseNamespaceChunks[] = $namespaceChunk;
if ($namespaceChunk == consoleBase::COMMANDS_DIRECTORY) {
break;
}
}
$namespace = str_replace(implode('\\', $baseNamespaceChunks), '', get_called_class());
$namespace = trim($namespace, '\\');
$commandNameData = explode('\\', $namespace);
$phpdoc = new DocBlock($reflection);
/** @var DocBlock\Tag $tag */
$tag = reset($phpdoc->getTagsByName('consoleNs'));
$commandNameValues = [];
if ($tag) {
$consoleNs = trim($tag->getDescription());
if (!empty($consoleNs)) {
$commandNameValues[] = $consoleNs;
}
}
foreach ($commandNameData as $commandNameValue) {
$commandNameValues[] = $commandNameValue;
}
$this->setName(implode(':', $commandNameValues))->setDescription($phpdoc->getShortDescription())->setHelp($phpdoc->getLongDescription());
$this->defineArguments();
}
示例4: getProperties
protected function getProperties($propertyName)
{
$reflection = new \ReflectionClass($this->model);
$docBlock = new DocBlock($reflection);
$properties = $docBlock->getTagsByName($propertyName);
return $this->buildProperties($properties);
}
示例5: extractPackageFromDocBlock
/**
* Extracts the package from the DocBlock.
*
* @param DocBlock $docBlock
*
* @return string|null
*/
protected function extractPackageFromDocBlock($docBlock)
{
$packageTags = $docBlock ? $docBlock->getTagsByName('package') : null;
if (!$packageTags) {
return null;
}
/** @var DocBlock\Tag $tag */
$tag = reset($packageTags);
return trim($tag->getContent());
}
示例6: getMethodDecorators
/**
* @param string $method
* @return array
*/
public function getMethodDecorators($method)
{
$reflectionMethod = new \ReflectionMethod($this->getInstance(), $method);
$docBlock = new DocBlock($reflectionMethod);
$decorators = [];
foreach ($docBlock->getTagsByName(static::TAG_NAME) as $tag) {
$decorators[] = $tag->getContent();
}
return $decorators;
}
示例7: detectType
/**
* @param \ReflectionProperty $reflectionProperty
*
* @return string|null
*/
public function detectType(\ReflectionProperty $reflectionProperty)
{
$docBlock = new DocBlock($reflectionProperty->getDocComment());
$tags = $docBlock->getTagsByName('var');
if (count($tags) == 0) {
return null;
}
/** @var VarTag $typeTag */
$typeTag = reset($tags);
return $typeTag->getType();
}
示例8: parsePropertyDocBlock
/**
*
* @param ReflectionProperty $reflector
* @return ParsePropertyBlockResult
*/
public function parsePropertyDocBlock(ReflectionProperty $reflector)
{
$phpdoc = new DocBlock($reflector->getDocComment());
/* @var $varTags VarTag[] */
$varTags = $phpdoc->getTagsByName("var");
/* @var $varTag VarTag */
$varTag = $varTags[0];
$result = new ParsePropertyBlockResult();
$result->description = $phpdoc->getShortDescription();
$result->type = (string) $varTag->getType();
return $result;
}
示例9: apply
/**
* Discover Magical API
*
* @param ClassNode $node
*/
public function apply(ClassNode $node)
{
$parentClass = $node->getParentClass();
$reflectionClass = new \ReflectionClass($parentClass);
$phpdoc = new DocBlock($reflectionClass->getDocComment());
$tagList = $phpdoc->getTagsByName('method');
foreach ($tagList as $tag) {
$methodNode = new MethodNode($tag->getMethodName());
$methodNode->setStatic($tag->isStatic());
$node->addMethod($methodNode);
}
}
示例10: __invoke
/**
* Given a property, attempt to find the type of the property.
*
* @param ReflectionProperty $reflectionProperty
* @return Type[]
*/
public function __invoke(ReflectionProperty $reflectionProperty)
{
$contextFactory = new ContextFactory();
$context = $contextFactory->createForNamespace($reflectionProperty->getDeclaringClass()->getNamespaceName(), $reflectionProperty->getDeclaringClass()->getLocatedSource()->getSource());
$docBlock = new DocBlock($reflectionProperty->getDocComment(), new DocBlock\Context($context->getNamespace(), $context->getNamespaceAliases()));
/* @var \phpDocumentor\Reflection\DocBlock\Tag\VarTag $varTag */
$resolvedTypes = [];
$varTags = $docBlock->getTagsByName('var');
foreach ($varTags as $varTag) {
$resolvedTypes = array_merge($resolvedTypes, (new ResolveTypes())->__invoke($varTag->getTypes(), $context));
}
return $resolvedTypes;
}
示例11: __invoke
/**
* Given a function and parameter, attempt to find the type of the parameter.
*
* @param ReflectionFunctionAbstract $function
* @param ParamNode $node
* @return Type[]
*/
public function __invoke(ReflectionFunctionAbstract $function, ParamNode $node)
{
$context = $this->createContextForFunction($function);
$docBlock = new DocBlock($function->getDocComment(), new DocBlock\Context($context->getNamespace(), $context->getNamespaceAliases()));
$paramTags = $docBlock->getTagsByName('param');
foreach ($paramTags as $paramTag) {
/* @var $paramTag \phpDocumentor\Reflection\DocBlock\Tag\ParamTag */
if ($paramTag->getVariableName() === '$' . $node->name) {
return (new ResolveTypes())->__invoke($paramTag->getTypes(), $context);
}
}
return [];
}
示例12: processDocBlocks
/**
* Process comments into docblock objects.
* @param array $docblocks
*/
protected function processDocBlocks(array $docblocks)
{
$this->docblocks = array();
foreach ($docblocks as $raw_docblock) {
$docblock = new DocBlock($raw_docblock);
$tags = $docblock->getTagsByName("var");
foreach ($tags as $tag) {
if ($tag && ($description = $tag->getDescription())) {
list($key, ) = explode(' ', $description);
$this->docblocks[$key] = $docblock;
}
}
}
}
示例13: setParentsPackage
protected function setParentsPackage(\DOMElement $parent, \phpDocumentor\Reflection\DocBlock $docblock, $element)
{
/** @var \phpDocumentor\Reflection\DocBlock\Tag $package */
$package = current($docblock->getTagsByName('package'));
/** @var \phpDocumentor\Reflection\DocBlock\Tag $subpackage */
$subpackage = current($docblock->getTagsByName('subpackage'));
$package_name = '';
if ($package) {
$package_name = str_replace(array('.', '_'), '\\', $package->getContent() . ($subpackage ? '\\' . $subpackage->getContent() : ''));
}
if (!$package_name) {
$package_name = $element->getDefaultPackageName();
}
$parent->setAttribute('package', $package_name);
}
示例14: getType
/**
* {@inheritdoc}
*
* @param Type $class
* @param string $name
* @return Type
*/
public function getType(Type $class, $name)
{
$reflectionObject = new ReflectionClass($class->toString());
if (!$reflectionObject->hasProperty($name)) {
return Type::fromString(null);
}
$reflectionProperty = $reflectionObject->getProperty($name);
$contextFactory = new ContextFactory();
$context = $contextFactory->createFromReflector($reflectionProperty);
$phpdoc = new DocBlock($reflectionProperty, $this->convertToDocBlockContext($context));
/** @var VarTag[] $vars */
$vars = $phpdoc->getTagsByName('var');
if (count($vars) === 0) {
return Type::fromString(null);
}
return Type::fromString($vars[0]->getType());
}
示例15: resolveElementType
/**
* @param \Reflector $reflector
* @param string $tagName
*
* @return string|null
*/
public function resolveElementType(\Reflector $reflector, $tagName)
{
$docBlock = new DocBlock($reflector);
$returnTags = $docBlock->getTagsByName($tagName);
/** @var ReturnTag $returnTag */
$returnTag = reset($returnTags);
$type = $returnTag->getType();
$isCollection = false;
if ($extractedType = $this->extractTypeFromCollectionType($type)) {
$isCollection = true;
$type = $extractedType;
}
if (static::isTypeObject($type) && ($reflector instanceof \ReflectionMethod || $reflector instanceof \ReflectionProperty)) {
$type = $this->resolveClassName($type, $reflector->getDeclaringClass());
}
return $type . ($isCollection ? '[]' : '');
}