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");
    

      

  • 相关阅读:
    Python易忽略要点记录二
    Python使用的几个小技巧
    MySQL内容整理二
    C++面向对象知识总结
    AssemblyInfo 的作用
    中国新年第一篇
    function函数的运用
    C语言1博客作业03
    C语言1博客作业02
    .C# 拷贝一个图片到指定文件夹下(IO文件操作实例)
  • 原文地址:https://www.cnblogs.com/cxscode/p/11365690.html
Copyright © 2011-2022 走看看