zoukankan      html  css  js  c++  java
  • laravel command命令行

    生成类

    为了创建一个新命令,你可以使用Artisan中的 command:make 命令生成一个骨架作为你的起点:

    生成一个命令类

    php artisan command:make FooCommand
    

    默认情况下,生成的类文件被存放在 app/commands 目录下,同时你也可以指定自定义目录和命名空间:

    php artisan command:make FooCommand --path=app/classes --namespace=Classes

    注册命令

    一旦你的命令完成后,你需要使用 Artisan 进行注册,这样才能够被使用。这通常在 app/start/artisan.php文件中完成。在这个文件中,你可以使用 Artisan::add 函数注册命令:

    注册一个 Artisan 命令

    Artisan::add(new CustomCommand);
    

    如果你的命令在应用程序的 IoC 容器 中注册,你可以使用 Artisan::resolve 函数使它对 Artisan 可用:

    注册一个在 IoC 容器中的命令

    Artisan::resolve('binding.name');

    一个发邮件样例:
    <?php
    
    use IlluminateConsoleCommand;
    use SymfonyComponentConsoleInputInputOption;
    use SymfonyComponentConsoleInputInputArgument;
    
    class SendMailCommand extends Command {
    
        /**
         * The console command name.
         *
         * @var string
         */
        protected $name = 'SendMailCommand:sendMail';//命令名,命令行调用使用php artisian 这里的$name值
    
        /**
         * The console command description.
         *
         * @var string
         */
        protected $description = 'send mail.';
    
        /**
         * Create a new command instance.
         *
         * @return void
         */
        public function __construct()
        {
            parent::__construct();
        }
    
        /**
         * Execute the console command.
         *
         * @return mixed
         */
        public function fire()
        {
            //
            $command=" C:/sendEmail -f from.sina.com -t to@qq.com  -s smtp.sina.com -xu username -xp pasword -u test ";
            $message=$this->argument('message');
            $str="$command -m $message ";
            $this->info($str);
            system($str);
             $this->info("It's Done, have a good day.");
            
        }
    
        /**
         * Get the console command arguments.
         *
         * @return array
         */
        protected function getArguments()
        {
            return array(
                 array('message', InputArgument::REQUIRED, 'An example argument.'),
            );
        }
    
        /**
         * Get the console command options.
         *
         * @return array
         */
        protected function getOptions()
        {
            return array(
                //array('example', null, InputOption::VALUE_OPTIONAL, 'An example option.', null),
            );
        }
    
    }

    运行:

    php artisan  commanname argx --option=bar --option=baz

    参考:

    http://www.golaravel.com/docs/4.0/commands/

    https://phphub.org/topics/34

    http://www.sitepoint.com/create-laravel-css-minify-command/

  • 相关阅读:
    C++学习(c++17)——2.X.使用string和string_view
    C++学习(c++17)——1.3一个小程序(part2.Datebase类)
    论++i + ++i + ++i
    C++学习(c++17)——1.3 一个小程序(part1.Employee类)
    C++学习(c++17)——1.2 稍微深入研究C++
    VS2019社区版关于Qt的设置
    C++学习(c++17)——1.1 C++基础知识
    2020杭电多校第五场
    2020杭电多校第四场
    2020杭电多校第三场
  • 原文地址:https://www.cnblogs.com/youxin/p/4191469.html
Copyright © 2011-2022 走看看