symplify/simple-php-doc-parser
最新稳定版本:10.0.25
Composer 安装命令:
composer require symplify/simple-php-doc-parser
包简介
Service integration of phpstan/phpdoc-parser, with few extra goodies for practical simple use
README 文档
README
Simple service integration of phpstan/phpdoc-parser, with few extra goodies for practical use
1. Install
composer require symplify/simple-php-doc-parser
2. Register Config
Register config in your config/config.php:
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; use Symplify\SimplePhpDocParser\ValueObject\SimplePhpDocParserConfig; return static function (ContainerConfigurator $containerConfigurator): void { $containerConfigurator->import(SimplePhpDocParserConfig::FILE_PATH); };
3. Usage of SimplePhpDocParser
Required services Symplify\SimplePhpDocParser\SimplePhpDocParser in constructor, where you need it, and use it:
use PHPStan\PhpDocParser\Ast\PhpDoc\ParamTagValueNode; use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocNode; use PHPStan\PhpDocParser\Ast\Type\TypeNode; use Symplify\SimplePhpDocParser\SimplePhpDocParser; final class SomeClass { /** * @var SimplePhpDocParser */ private $simplePhpDocParser; public function __construct(SimplePhpDocParser $simplePhpDocParser) { $this->simplePhpDocParser = $simplePhpDocParser; } public function some(): void { $docBlock = '/** @param int $name */'; /** @var PhpDocNode $phpDocNode */ $simplePhpDocNode = $this->simplePhpDocParser->parseDocBlock($docBlock); // param extras /** @var TypeNode $nameParamType */ $nameParamType = $simplePhpDocNode->getParamType('name'); /** @var ParamTagValueNode $nameParamTagValueNode */ $nameParamTagValueNode = $simplePhpDocNode->getParam('name'); } }
4. Traverse Nodes with PhpDocNodeTraverser
use PHPStan\PhpDocParser\Ast\Node; use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocNode; use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode; use PHPStan\PhpDocParser\Ast\PhpDoc\VarTagValueNode; use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode; use Symplify\SimplePhpDocParser\PhpDocNodeTraverser; use Symplify\SimplePhpDocParser\PhpDocNodeVisitor\AbstractPhpDocNodeVisitor; use Symplify\SimplePhpDocParser\PhpDocNodeVisitor\CallablePhpDocNodeVisitor; $phpDocNodeTraverser = new PhpDocNodeTraverser(); $phpDocNode = new PhpDocNode([new PhpDocTagNode('@var', new VarTagValueNode(new IdentifierTypeNode('string')))]); // A. you can use callable to traverse $callable = function (Node $node): Node { if (! $node instanceof VarTagValueNode) { return $node; } $node->type = new IdentifierTypeNode('int'); return $node; }; $callablePhpDocNodeVisitor = new CallablePhpDocNodeVisitor($callable, null); $phpDocNodeTraverser->addPhpDocNodeVisitor($callablePhpDocNodeVisitor); // B. or class that extends AbstractPhpDocNodeVisitor final class IntegerPhpDocNodeVisitor extends AbstractPhpDocNodeVisitor { /** * @return Node|int|null */ public function enterNode(Node $node) { if (! $node instanceof VarTagValueNode) { return $node; } $node->type = new IdentifierTypeNode('int'); return $node; } } $integerPhpDocNodeVisitor = new IntegerPhpDocNodeVisitor(); $phpDocNodeTraverser->addPhpDocNodeVisitor($integerPhpDocNodeVisitor); // then traverse the main node $phpDocNodeTraverser->traverse($phpDocNode);
symplify/simple-php-doc-parser 适用场景与选型建议
symplify/simple-php-doc-parser 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.9M 次下载、GitHub Stars 达 24, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 symplify/simple-php-doc-parser 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 symplify/simple-php-doc-parser 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 1.9M
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 24
- 点击次数: 29
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 未知