电缆 / 电缆注释
电缆框架的注释库
1.0.9
2017-06-27 14:08 UTC
Requires
- psr/container: ^1.0
Requires (Dev)
- cable/cable-container: ^1.2
README
电缆框架的PHP注释库
需求
PHP 5.6+
安装
composer require cable/cable-annotations
use Cable\Annotation\Factory; $annotation = Factory::create();
添加命令
/** * * @Name("Test") the name of command * */ class TestCommand extends Command{ /** * * @Annotation() // you must add this * // if you want to use that property * * @Required() // if this parameter not given by user, * //will be thrown a exception * * @Default('Default value'); // default value of property * // if you set this, required exception will be never thrown * // so there is no point of using together Default and Required */ public $name; } $annotation->addCommand(new TestCommand());
使用命令
class Test{ /** * * @Test(name = "test name") * * */ public function testing(){ } } // execute the class instance $class = $annotation->executeClass(new Test()); $methods = $annotation->methods(); // $annotation->get('methods') // same as above // $methods->get('Test'); foreach($methods->Test() as $test){ echo $test->name; // test name will be printed }
使用参数
提供数组
/** * * @Test(datas={test: "test"}) * * will be given as ["test" = "test"] * */
将注释放入数据中
/** * * @Test(data= @Test(name = "data")) * * * // you can give @Test into data */
保存容器
您可以将任何psr-11容器提供给注释
Annotation::setContainer($container); `` ```php /** * * @Test(data= aliasname{test:"test"}) * * * // you must save aliasname into the container */