1. Go to this page and download the library: Download jasny/phpdoc-parser library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
jasny / phpdoc-parser example snippets
/**
* The description of foo. This function does a lot of thing
* which are described here.
*
* Some more text here.
*
* @important
* @uses FooReader
* @internal Why this isn't part of the API.
* Multi-line is supported.
*
* @param string|callable $first This is the first param
* @param int $second The second one
* @return void
* @throws InvalidArgumentException
* @throws DoaminException if first argument is not found
*/
function foo($first, int $second)
{
// ...
}
use Jasny\PhpdocParser\PhpdocParser;
use Jasny\PhpdocParser\Set\PhpDocumentor;
use Jasny\PhpdocParser\Tag\FlagTag;
$doc = (new ReflectionFunction('foo'))->getDocComment();
$customTags = [
new FlagTag('important')
];
$tags = PhpDocumentor::tags()->with($customTags);
$parser = new PhpdocParser($tags);
$meta = $parser->parse($doc);
[
'summery' => "The description of foo",
'description' => "The description of foo. This function does a lot of thing which are described here.\n\nSome more text.",
'important' => true,
'uses' => 'FooReader',
'internal' => "Why this isn't part of the API. Mutlti-line is supported",
'params' => [
'first' => [
'type' => "string|callable",
'name' => "first",
'description' => "This is the first parm"
],
'second' => [
'type' => "int",
'name' => "second",
]
],
'return' => 'void'
]
use Jasny\PhpdocParser\PhpdocParser;
use Jasny\PhpdocParser\Set\PhpDocumentor;
//$doc = ...; Get doc-comment string from reflection
$tags = PhpDocumentor::tags();
$parser = new PhpdocParser($tags);
$meta = $parser->parse($doc);
use Jasny\PhpdocParser\PhpdocParser;
use Jasny\PhpdocParser\Set\PhpDocumentor;
use phpDocumentor\Reflection\Types\ContextFactory;
use phpDocumentor\Reflection\FqsenResolver;
$reflection = new ReflectionClass('\My\Example\Classy');
$contextFactory = new ContextFactory();
$context = $contextFactory->createFromReflector($reflection);
$resolver = new FqsenResolver();
$fn = fn(string $class): string => $resolver->resolve($class, $context);
$tags = PhpDocumentor::tags($fn);
$parser = new PhpdocParser($tags);
$doc = $reflection->getDocComment();
$meta = $parser->parse($doc);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.