zoukankan      html  css  js  c++  java
  • lavavel 定时任务 (command的第二个参数)

    之前好像没有写过,记录一下

    $schedule->command()方法

    第一个参数不用说,可以传纯字符串或者类::class,不过第二个参数确很少人提到

    /**
         * Add a new Artisan command event to the schedule.
         *
         * @param  string  $command
         * @param  array  $parameters
         * @return IlluminateConsoleSchedulingEvent
         */
        public function command($command, array $parameters = [])
        {
            if (class_exists($command)) {
                $command = Container::getInstance()->make($command)->getName();
            }
    
            return $this->exec(
                Application::formatCommandString($command), $parameters
            );
        }
    

     如上第二个参数是数组,看了源码是拼接在命令后面,如果你传二维数组,它也是只会解析排列在命令后面,

    /**
         * Compile parameters for a command.
         *
         * @param  array  $parameters
         * @return string
         */
        protected function compileParameters(array $parameters)
        {
            return collect($parameters)->map(function ($value, $key) {
                if (is_array($value)) {
                    $value = collect($value)->map(function ($value) {
                        return ProcessUtils::escapeArgument($value);
                    })->implode(' ');
                } elseif (! is_numeric($value) && ! preg_match('/^(-.$|--.*)/i', $value)) {
                    $value = ProcessUtils::escapeArgument($value);
                }
    
                return is_numeric($key) ? $value : "{$key}={$value}";
            })->implode(' ');
        }
    

     具体是这个方法

    传入 [‘a’, 'b'] 解析完 'a' 'b'
    传入 [[‘a’, 'b'], 'c'] 解析完 'a' 'b' 'c'
    

      

     也可以在方法里触发定时任务

    Artisan::call("order:log");
    

      

  • 相关阅读:
    com.alibaba.fastjson.JSONException: default constructor not found. class ……
    ActiveMQ伪集群部署
    #{}和${}的区别
    微信小程序——报错汇总
    PHP——base64的图片的另类上传方法
    PHP——base64的图片转为文件图片
    veu——引入iconfont图标
    vue——script内容详解
    webpack——阮一峰webpackDemo分析
    webpack——快速入门【一】
  • 原文地址:https://www.cnblogs.com/cxscode/p/11365690.html
Copyright © 2011-2022 走看看