schneidoa / php-easy-annotation
简单的PHP注解库
v1.0.1
2016-07-08 22:32 UTC
Requires
- php: >=5.6
Requires (Dev)
- phpunit/phpunit: 5.4.*
This package is auto-updated.
Last update: 2024-09-27 07:44:29 UTC
README
由 Daniel Schneider 创建
介绍
PHPEasyAnnotation是一个简单的PHP注解库。它设计得非常简单且易于扩展。
要求
- PHP>=5.6
- 反射
DEV
- phpunit/phpunit: "5.4.*"
安装
主要设置
使用composer
-
将此项目添加到您的composer.json中
"require": { "schneidoa/php-easy-annotation": "dev-master" }
-
现在让composer下载PHPEasyAnnotation
$ php composer.phar update
用法
class Example { /** * * @Column(user_id) * @Json({"data": 1}) */ public $userId; /** * * @Column(username) * @NotNull() * @Json({"data": "dummy"}) */ public $username; }
示例 1
use Schneidoa\EasyAnnotation\EasyAnnotationClass; use Schneidoa\EasyAnnotation\EasyAnnotationProperty; $p = new EasyAnnotationClass(get_class($this)); $p = $p->getAnnotationProperty('userId'); var_dump( $p->getAnnotations());
PHP 输出
array (size=2) 0 => array (size=3) 'annotation' => string '@Column(user_id)' (length=16) 'name' => string 'Column' (length=6) 'value' => string 'user_id' (length=7) 1 => array (size=3) 'annotation' => string '@Json({"data": 1})' (length=18) 'name' => string 'Json' (length=4) 'value' => array (size=1) 'data' => int 1
示例 2
$p = new EasyAnnotationClass(get_class($this)); $properties = $p->getAnnotationProperties(); foreach($properties as $property){ var_dump($property->getAnnotations()); }
PHP 输出
array (size=2) 0 => array (size=3) 'annotation' => string '@Column(user_id)' (length=16) 'name' => string 'Column' (length=6) 'value' => string 'user_id' (length=7) 1 => array (size=3) 'annotation' => string '@Json({"data": 1})' (length=18) 'name' => string 'Json' (length=4) 'value' => array (size=1) 'data' => int 1 array (size=3) 0 => array (size=3) 'annotation' => string '@Column(username)' (length=17) 'name' => string 'Column' (length=6) 'value' => string 'username' (length=8) 1 => array (size=3) 'annotation' => string '@NotNull()' (length=10) 'name' => string 'NotNull' (length=7) 'value' => string '' (length=0) 2 => array (size=3) 'annotation' => string '@Json({"data": "dummy"})' (length=24) 'name' => string 'Json' (length=4) 'value' => array (size=1) 'data' => string 'dummy' (length=5)