thinkphp6给命令行添加develop和product环境变量
2022-07-01 12:01 wish123 阅读(291) 评论(0) 编辑 收藏 举报thinkphp6给命令行添加develop和product环境变量的方法如下:
一、think 文件中代码改为:
$cmdLine = implode(' ', $argv); if(strpos($cmdLine, '--env') && (strpos($cmdLine, 'dev') || strpos($cmdLine, 'develop'))) { define('ENV', 'develop'); (new App())->setEnvName(ENV)->console->run(); } else { define('ENV', 'product'); (new App())->console->run(); }
二、app下增加app/Console.php文件,Console.php文件内容如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | <?php namespace app; use think\console\input\Argument as InputArgument; use think\console\input\Definition as InputDefinition; use think\console\input\Option as InputOption; class Console extends \think\Console { protected function getDefaultInputDefinition(): InputDefinition { return new InputDefinition([ new InputArgument( 'command' , InputArgument::REQUIRED, 'The command to execute' ), new InputOption( '--help' , '-h' , InputOption::VALUE_NONE, 'Display this help message' ), new InputOption( '--version' , '-V' , InputOption::VALUE_NONE, 'Display this console version' ), new InputOption( '--quiet' , '-q' , InputOption::VALUE_NONE, 'Do not output any message' ), new InputOption( '--verbose' , '-v|vv|vvv' , InputOption::VALUE_NONE, 'Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug' ), new InputOption( '--ansi' , '' , InputOption::VALUE_NONE, 'Force ANSI output' ), new InputOption( '--no-ansi' , '' , InputOption::VALUE_NONE, 'Disable ANSI output' ), new InputOption( '--no-interaction' , '-n' , InputOption::VALUE_NONE, 'Do not ask any interactive question' ), new InputOption( '--no-interaction' , '-n' , InputOption::VALUE_NONE, 'Do not ask any interactive question' ), new InputOption( '--env' , '-env' , InputOption::VALUE_OPTIONAL, 'Environment variable settings' ), ]); } } |
三、app\provider.php文件中增加'console'=> Console::class, 如下:
1 2 3 4 5 | return [ 'think\Request' => Request:: class , 'think\exception\Handle' => ExceptionHandle:: class , 'console' => Console:: class , ]; |
四、使用
php think your-ommand --env=dev
php think queue:work --queue=yourQueue --env dev
声明:本站部分图片或文章内容来源于网络,版权归原作者所有,如有侵权,请与我联系删除。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 周边上新:园子的第一款马克杯温暖上架