https://github.com/smuuf/php-docblock-parser
Just a simple PHP docblock text parser.
https://github.com/smuuf/php-docblock-parser
Last synced: 2 months ago
JSON representation
Just a simple PHP docblock text parser.
- Host: GitHub
- URL: https://github.com/smuuf/php-docblock-parser
- Owner: smuuf
- License: mit
- Created: 2021-10-25T00:13:29.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2021-12-11T01:33:09.000Z (over 3 years ago)
- Last Synced: 2025-02-15T01:30:55.682Z (4 months ago)
- Language: PHP
- Size: 15.6 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://github.com/smuuf/php-docblock-parser/actions/workflows/php.yml)
# PHP Docblock Text Parser
Simple tool to parse PHP docblock text with ability to also read tags and their arguments in form:
```
/**
* Some text.
*
* @whatever-tags(with-arguments: yes, or-even=these)
*/
```... or you can parse text directly even without the block comment wrapping:
```
Some text.@whatever-tags(with-arguments: yes, or-even=these)
```## Results of parsing
- `DocBlock`
- Comment text _(title + body)_
- Comment title
- Comment body
- `Tag` objects
- Tag name
- `TagArg` objects
- Tag argument name
- Tag argument Value
## Example usage``````php
hasTitle(); // true
$docBlock->getTitle(); // "Lorem ipsum dolor sit amet."
$docBlock->getBody(); // "Consectetuer adipiscing elit. Nulla quis diam ..."
$docBlock->getText(); // "Lorem ipsum dolor sit amet. Consectetuer ..."//
// Tags.
//$docBlock->getTags(); // Tags object containing all tags.
$docBlock->hasTag('tag1'); // true
$docBlock->hasTag('tag2.abc'); // true
$docBlock->hasTag('tag3'); // true
$docBlock->hasTag('tag999lol'); // false//
// Single tag.
//$tag = $docBlock->getTags('tag2.abc')->getFirst(); // Instance of Tag object.
$tag->getArgs(); // A dict array of [tag_arg_name => TagArg object]//
// Multiple tags with the same name.
//$docBlock->getTags('tag3')->getAll(); // List array [, ]
$tag = $docBlock->getTags('tag3')->getFirst(); // Instance of Tag object for the tag "@tag3".
$tag->getArgs(); // An empty array.//
// Tag args.
//$tag = $docBlock->getTags('tag2.abc')->getFirst();
$tag->hasArg('arg1'); // true
$tag->hasArg('arg2'); // true
$tag->hasArg('arg999'); // false$tagArg = $tag->getArg('arg2'); // Instance of TagArg object.
$tagArg->getName(); // "arg2"
$tagArg->getValue(); // "no"$tagArg = $tag->getArg('arg3-without-value'); // Instance of TagArg object.
$tagArg->getName(); // "arg3-without-value"
$tagArg->getValue(); // null
``````