waiterphp / builder
waiterphp builder
Installs: 34
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 4
Forks: 0
Open Issues: 0
Language:JavaScript
Requires
- php: >=5.4.0
- waiterphp/core: >0.0.0
This package is not auto-updated.
Last update: 2024-11-02 03:45:16 UTC
README
waiterphp 的代码生成框架,用于生成特定应用或自定义的代码片段
命令行入口文件说明
-
建议将文件放置在项目根目录下
-
代码示例:
#!/usr/bin/env php <?php require \_\_DIR\_\_ . '/start.php'; use Builder\Application; use Builder\Input\Input; use Builder\Output\Output; /*注册项目命令文件夹*/ Application::addCommandNamespace(array('Command\\' => __DIR__.'/command'), $autoloader); //运行命令 Application::getInstance()->run(new Input(), new Output());
命令行目录
在项目更目录中建立command,则像下面这样注册
- 'Command\' 为命名空间
- DIR.'/command' 命令行所在的文件夹
- $autoloader 自动加载的对象
- waiterphp项目的start.php文件13行修改为 file_exists($composerFile) && $autoloader = include($composerFile);
Application::addCommandNamespace(array('Command\\' => __DIR__.'/command'), $autoloader);
命令文件书写示例
- 控制器示例
<?php namespace Command; use Builder\Command\Command as BuildCommand; use Builder\Input\InputInterface; use Builder\Output\OutputInterface; class Controller extends BuildCommand { public $name = 'controller'; public $description = '创建控制器'; public function execute(InputInterface $input, OutputInterface $output) { $commandName = $input->get(0) . '......'; $output->writeln('正在执行命令:' . $output->color($commandName, \Builder\Output\Color::F_GREEN)); //命令之间的调用 命令名 传入的参数 如果调用的命令 php build controller -t sample_admin 则下面的参数可以省略model会直接从命令行参数取得 parent::call('model', array('t'=>'sample_admin')); } }
其中有命令行调用
2. 模型示例:
<?php namespace Command; use Builder\Command\Command as BuildCommand; use Builder\Input\InputInterface; use Builder\Output\OutputInterface; class Model extends BuildCommand { public $name = 'model'; public $description = '创建表模型'; public function execute(InputInterface $input, OutputInterface $output) { $tableName = $input->get('t'); $output->writeln('要创建model的表名为:' . $output->color($tableName, \Builder\Output\Color::F_GREEN)); } }