php-platform / annotations
此包的最新版本(v0.1.2)没有可用的许可信息。
v0.1.2
2018-06-26 14:00 UTC
Requires
- php: >=5.3
Requires (Dev)
- phpunit/phpunit: ~4.8
This package is not auto-updated.
Last update: 2024-09-28 20:03:49 UTC
README
此包提供了访问PHP中注解的API
用法
获取注解
PhpPlatform\Annotations\Annotation::getAnnotations($className, $propertyName="*", $constantName="*", $methodName="*");
其中
$className是需要注解的类的完整名称$propertyName是需要注解的属性字符串或属性数组$constantName是需要注解的常量字符串或常量数组$methodName是需要注解的方法名称字符串或方法名称数组
声明注解
此库支持DocComments注解,注解声明格式为
* @KEY VALUE(S)
其中 KEY 可以包含通过 . 分隔的子键,而 VALUES 是通过 空格 或 逗号 分隔的字符串
示例
此示例展示了不同形式的注解及其预期值
/** * @key1 * @key2 * @key3.subKey1 * @key3.subKey2.subkey21 success * @key4 v1 * @key5 (v2) * @key6 v3 v4 * @key7 "v5\"With Space and Quotes\"" * @key8 ("v6\"With Space and Quotes\"", v7) * @key9 ("v8\"With Space and Quotes\"", v9) description1 * @key10 ("v10 With \\", v11) description2 * @key11 ("123", v12) description3 * @key12 ("true", "false") * @key13 v13 * @key13 1234 * @key14 (v14) * @key14 v15 * @ notKey * @wrongKey(v16) desc * */ public $testDifferrentFormatsOfAnnoptations;
从
PhpPlatform\Annotations\Annotation::getAnnotations($className, 'testDifferrentFormatsOfAnnoptations');
返回的注解数组将是
[
"testDifferrentFormatsOfAnnoptations" => [
"key1" => true,
"key2" => true,
"key3" => [
"subKey1" => true,
"subKey2" => [
"subkey21" => "success"
]
],
"key4" => "v1",
"key5" => ["v2"],
"key6" => ["v3", "v4"],
"key7" => 'v5"With Space and Quotes"',
"key8" => ['v6"With Space and Quotes"', "v7"],
"key9" => ['v8"With Space and Quotes"', "v9"],
"key10" => ["v10 With \\", "v11"],
"key11" => [123, "v12"],
"key12" => [true, false],
"key13" => ['v13', 1234],
"key14" => ["v14", "v15"]
]
]