{"id":37004691,"url":"https://github.com/panlatent/annotation","last_synced_at":"2026-01-14T00:38:45.313Z","repository":{"id":57035662,"uuid":"84579192","full_name":"panlatent/annotation","owner":"panlatent","description":"Parsing PHPDoc style annotations from comments (Support PSR-5 DRAFT)","archived":true,"fork":false,"pushed_at":"2017-06-16T02:08:46.000Z","size":80,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-07-19T08:35:08.866Z","etag":null,"topics":["annotation-processor","annotations","phpdoc","phpdoc-parser","psr-5"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/panlatent.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-03-10T16:28:46.000Z","updated_at":"2024-04-12T09:44:41.000Z","dependencies_parsed_at":"2022-08-23T20:50:58.213Z","dependency_job_id":null,"html_url":"https://github.com/panlatent/annotation","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/panlatent/annotation","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/panlatent%2Fannotation","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/panlatent%2Fannotation/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/panlatent%2Fannotation/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/panlatent%2Fannotation/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/panlatent","download_url":"https://codeload.github.com/panlatent/annotation/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/panlatent%2Fannotation/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28406520,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-13T21:51:37.118Z","status":"ssl_error","status_checked_at":"2026-01-13T21:45:14.585Z","response_time":56,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["annotation-processor","annotations","phpdoc","phpdoc-parser","psr-5"],"created_at":"2026-01-14T00:38:45.230Z","updated_at":"2026-01-14T00:38:45.299Z","avatar_url":"https://github.com/panlatent.png","language":"PHP","readme":"# Annotation\n[![Build Status](https://travis-ci.org/panlatent/annotation.svg)](https://travis-ci.org/panlatent/annotation)\n[![Latest Stable Version](https://poser.pugx.org/panlatent/annotation/v/stable.svg)](https://packagist.org/packages/panlatent/annotation) \n[![Total Downloads](https://poser.pugx.org/panlatent/annotation/downloads.svg)](https://packagist.org/packages/panlatent/annotation) \n[![Latest Unstable Version](https://poser.pugx.org/panlatent/annotation/v/unstable.svg)](https://packagist.org/packages/panlatent/annotation) \n[![License](https://poser.pugx.org/panlatent/annotation/license.svg)](https://packagist.org/packages/panlatent/annotation)\n\nParsing PHPDoc style annotations from comments.\n\nAnnotation 是一个 PHPDoc 风格注释解析器，它能从注释里面解析 PHPDoc 注释元素并封装成对应的类。为了保证对 PHPDoc 注释解析的一致性，\nAnnotation 遵循 [PSR-5 PHPDoc草案](https://github.com/phpDocumentor/fig-standards/blob/master/proposed/phpdoc.md)。\n与其他大多数库不同，它的解析器通过词法分析来解析 PHPDoc 。\n\n它的目的是帮助用户轻松的获取 PHPDoc 注释中包含的信息。你可以使用它构建你的项目。使用继承关系特化标签或是创建自定义标签。\n\n## Usage\n\n### 仅解析 PHPDoc\n\n如果只需要解析 PHPDoc，仅需要构造解析器并调用 `Parser::parser()` 方法：\n```php\n$docBlock = \u003c\u003c\u003cDOC\n/**\n * This is a phpdoc.\n */\nDOC;\n\n$parser = new Panlatent\\Annotation\\Parser();\n$phpdoc = $parser-\u003eparser($docBlock);\n\necho $phpdoc-\u003egetSummary(); // Output: \"This is a phpdoc.\"\n```\n\n### 解析 PHP 代码（使用反射）\n\n```php\n$parser = new Panlatent\\Annotation\\Parser();\n$annotation = new AnnotationClass(ExampleClass::class, $parser);\n```\n\n### 自定义标签\n\n#### 注册\n\n自定义标签需要注册到 `TagFactory` 中，如果解析时发现未注册标签，将按照类似 `PSR-4` 的规则进行类查找。\n\n```php\n$factory = new Panlatent\\Annotation\\TagFactory();\n$factory-\u003eadd('api', Panlatent\\Annotation\\Tag\\ApiTag::class);\n$parser = new Parser($factory);\n```\n或者\n```php\n$parser = new Parser();\n$factory = $parser-\u003egetTagFactory();\n$factory-\u003eadd('api', Panlatent\\Annotation\\Tag\\ApiTag::class);\n```\n\n#### 创建\n\n创建一个类, 继承自 `Panlatent\\Annotation\\Parser\\Tag` 或实现 `Panlatent\\Annotation\\Parser\\TagInterface`，类名后缀为 `Tag`。\n\n例如，创建一个 `\\panlatent\\annotation\\add` 标签, 类名为 `Panlatent\\Annotation\\AddTag`。\n```php\n/**\n * @\\panlatent\\annotation\\add // 最前面的 '/' 不是必须的\n */\n```\n\n也可以创建一个别名，这需要你提前将别名注册，并绑定到一个类上：\n```php\n/**\n * @add\n */\n```\n\n### 特化标签\n\n特化标签形如 `@api:restful` ，推荐使用类的继承关系表示特化。特化标签与普通标签类明明规则相同。\n例如，特化 `@api` 标签 `@api:restful`，对应类名为 `ApiRestfulTag`。\n\n```php\n/**\n * @api:restful post\n */\n```\n\n## Parser\n\nAnnotation 的解析器由 4 个部分组成，包括预处理器、字符流生成器、词法分析器、语法分析器。\n\n+ **预处理器**是用来过滤包裹 PHPDoc `*` 符号或者无意义空白的工具。它可以将 `*` 替换为等效的空格，目的是保留原始字符串的未知\n信息，也可以仅保留有效的PHPDoc。\n\n+ **字符流生成器**是用来生成字符流的类，专门针对字符流提供迭代器、预期和回溯操作、并提供字符的行号、列号和上下文信息。\n\n+ **词法分析器**会将字符流生成器送来的字符按照一定规则解析成 Token 。生成的 Token 以 yield (Generator PHP5.5+) 的方式输出，\n并在必要的时候抛出异常。\n\n+ **语法分析器**从词法分析器中接受 Token 流，分析并生成语法树并组装成PHP类结构。\n\n## License\n\nThe Annotation is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT).","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpanlatent%2Fannotation","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpanlatent%2Fannotation","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpanlatent%2Fannotation/lists"}