PHPackages                             panlatent/annotation - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. panlatent/annotation

AbandonedArchivedLibrary[Parsing &amp; Serialization](/categories/parsing)

panlatent/annotation
====================

Parsing PHPDoc style annotations from comments

028PHP

Since Apr 12Pushed 9y ago1 watchersCompare

[ Source](https://github.com/panlatent/annotation)[ Packagist](https://packagist.org/packages/panlatent/annotation)[ RSS](/packages/panlatent-annotation/feed)WikiDiscussions master Synced 4w ago

READMEChangelogDependenciesVersions (1)Used By (0)

Annotation
==========

[](#annotation)

[![Build Status](https://camo.githubusercontent.com/c0fadde2caceeb09d08f53f7e75a0374f69080acae55d877b5f9d2d32e189f21/68747470733a2f2f7472617669732d63692e6f72672f70616e6c6174656e742f616e6e6f746174696f6e2e737667)](https://travis-ci.org/panlatent/annotation)[![Latest Stable Version](https://camo.githubusercontent.com/b2d48cdfb22c39381ee58e3b875c9947058afb35603bc981f31e34ff674138cf/68747470733a2f2f706f7365722e707567782e6f72672f70616e6c6174656e742f616e6e6f746174696f6e2f762f737461626c652e737667)](https://packagist.org/packages/panlatent/annotation)[![Total Downloads](https://camo.githubusercontent.com/7c2dfeddd4e2f6f06b628bea007807c0c6893c30f1a6515f0816490c93368621/68747470733a2f2f706f7365722e707567782e6f72672f70616e6c6174656e742f616e6e6f746174696f6e2f646f776e6c6f6164732e737667)](https://packagist.org/packages/panlatent/annotation)[![Latest Unstable Version](https://camo.githubusercontent.com/c0f4c9dc27258b141818f752435805abba85f6e124c357a371537a395986cb34/68747470733a2f2f706f7365722e707567782e6f72672f70616e6c6174656e742f616e6e6f746174696f6e2f762f756e737461626c652e737667)](https://packagist.org/packages/panlatent/annotation)[![License](https://camo.githubusercontent.com/811ca9326359bc2be0d9249392678255a4974797bfd4a388ac8e8a446d7e8549/68747470733a2f2f706f7365722e707567782e6f72672f70616e6c6174656e742f616e6e6f746174696f6e2f6c6963656e73652e737667)](https://packagist.org/packages/panlatent/annotation)

Parsing PHPDoc style annotations from comments.

Annotation 是一个 PHPDoc 风格注释解析器，它能从注释里面解析 PHPDoc 注释元素并封装成对应的类。为了保证对 PHPDoc 注释解析的一致性， Annotation 遵循 [PSR-5 PHPDoc草案](https://github.com/phpDocumentor/fig-standards/blob/master/proposed/phpdoc.md)。 与其他大多数库不同，它的解析器通过词法分析来解析 PHPDoc 。

它的目的是帮助用户轻松的获取 PHPDoc 注释中包含的信息。你可以使用它构建你的项目。使用继承关系特化标签或是创建自定义标签。

Usage
-----

[](#usage)

### 仅解析 PHPDoc

[](#仅解析-phpdoc)

如果只需要解析 PHPDoc，仅需要构造解析器并调用 `Parser::parser()` 方法：

```
$docBlock = add('api', Panlatent\Annotation\Tag\ApiTag::class);
$parser = new Parser($factory);
```

或者

```
$parser = new Parser();
$factory = $parser->getTagFactory();
$factory->add('api', Panlatent\Annotation\Tag\ApiTag::class);
```

#### 创建

[](#创建)

创建一个类, 继承自 `Panlatent\Annotation\Parser\Tag` 或实现 `Panlatent\Annotation\Parser\TagInterface`，类名后缀为 `Tag`。

例如，创建一个 `\panlatent\annotation\add` 标签, 类名为 `Panlatent\Annotation\AddTag`。

```
/**
 * @\panlatent\annotation\add // 最前面的 '/' 不是必须的
 */
```

也可以创建一个别名，这需要你提前将别名注册，并绑定到一个类上：

```
/**
 * @add
 */
```

### 特化标签

[](#特化标签)

特化标签形如 `@api:restful` ，推荐使用类的继承关系表示特化。特化标签与普通标签类明明规则相同。 例如，特化 `@api` 标签 `@api:restful`，对应类名为 `ApiRestfulTag`。

```
/**
 * @api:restful post
 */
```

Parser
------

[](#parser)

Annotation 的解析器由 4 个部分组成，包括预处理器、字符流生成器、词法分析器、语法分析器。

- **预处理器**是用来过滤包裹 PHPDoc `*` 符号或者无意义空白的工具。它可以将 `*` 替换为等效的空格，目的是保留原始字符串的未知 信息，也可以仅保留有效的PHPDoc。
- **字符流生成器**是用来生成字符流的类，专门针对字符流提供迭代器、预期和回溯操作、并提供字符的行号、列号和上下文信息。
- **词法分析器**会将字符流生成器送来的字符按照一定规则解析成 Token 。生成的 Token 以 yield (Generator PHP5.5+) 的方式输出， 并在必要的时候抛出异常。
- **语法分析器**从词法分析器中接受 Token 流，分析并生成语法树并组装成PHP类结构。

License
-------

[](#license)

The Annotation is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT).

###  Health Score

20

—

LowBetter than 13% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/c79a4220751bab4ff8ee0953a41c4664fddb12e2a47e69442c2e5315b5c7ef9a?d=identicon)[panlatent](/maintainers/panlatent)

---

Top Contributors

[![panlatent](https://avatars.githubusercontent.com/u/4393268?v=4)](https://github.com/panlatent "panlatent (56 commits)")

---

Tags

annotation-processorannotationsphpdocphpdoc-parserpsr-5

### Embed Badge

![Health badge](/badges/panlatent-annotation/health.svg)

```
[![Health](https://phpackages.com/badges/panlatent-annotation/health.svg)](https://phpackages.com/packages/panlatent-annotation)
```

###  Alternatives

[mck89/peast

Peast is PHP library that generates AST for JavaScript code

19139.2M44](/packages/mck89-peast)[sauladam/shipment-tracker

Parses tracking information for several carriers, like UPS, USPS, DHL and GLS by simply scraping the data. No need for any kind of API access.

9843.5k](/packages/sauladam-shipment-tracker)[moonshine/layouts-field

Field for repeating groups of fields for MoonShine

108.5k](/packages/moonshine-layouts-field)[tcds-io/php-jackson

A lightweight, flexible object serializer for PHP, inspired by FasterXML/jackson

113.2k10](/packages/tcds-io-php-jackson)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
