<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                [TOC] ## **Command** ### **屬性** | 屬性名 | 描述 |參數類型|默認值|權限| | --- | --- | --- | --- | --- | | $input | | Input | void | protected | | $output | | Output | void | protected | ### **方法** | 方法名 | 描述 |參數說明|返回值|權限| | --- | --- | --- | --- | --- | | __construct($name = null) | 構造方法 | string\|null $name 命令名稱,如果沒有設置則比如在 configure() 里設置 |void| public | | ignoreValidationErrors() | 忽略驗證錯誤 |void| void | public | | setConsole(Console $console = null) | 設置控制臺 |Console| void | public | | getConsole() | 獲取控制臺 | void | Console |public| | isEnabled() | 是否有效 | void |直接返回true| public | | **configure**() | 配置指令,留給子類進行自定義命令參數配置 | void | void | protected | | **execute**(Input $input, Output $output) | 執行指令,留給子類進行自定義命令執行程序的接口 | Input,Output | null\|int | protected | | run(Input $input, Output $output) | 執行 | Input,Output | int | public | | setCode(callable $code) | 設置執行代碼 | callable(InputInterface $input, OutputInterface $output) | Command | public | | mergeConsoleDefinition($mergeArgs = true) | 合并參數定義 | 合并的參數 | void | public | | setDefinition($definition) | 設置參數定義 | array\|Definition $definition | Command |public | | getDefinition() | 獲取參數定義 | void | Definition | public | | getNativeDefinition() | 獲取當前指令的參數定義 | void | Definition | public | | **addArgument**($name, $mode = null, $description = '', $default = null) | 添加參數 | string $name 名稱<br>int $mode 類型<br>string $description 描述<br>mixed $default 默認值 | Command | public | | **addOption**($name, $shortcut = null, $mode = null, $description = '', $default = null) | 添加選項 添加后 使用時跟在參數后面,前面加-- | string $name 選項名稱<br>string $shortcut 別名<br>int $mode 類型<br>string $description 描述<br>mixed $default 默認值 | Command | public | | **setName**($name) | 設置指令名稱 | string $name | Command | public | | getName() | 獲取指令名稱 | void | String 指令名稱 |public | | **setDescription**($description) | 設置描述 | string $description | Command |public | | getDescription() | 獲取描述 | void | string 描述 |public | | setHelp($help) | 設置幫助信息 | string $help | Command |public | | getHelp() | 獲取幫助信息 | void | string 設置的幫助信息 |public | | getProcessedHelp() | 獲取描述信息 | void | string 描述信息 |public | | setAliases($aliases) | 設置別名 | string[] $aliases | Command |public | | getAliases() | 獲取別名 | void | array |public | | getSynopsis($short = false) | 獲取簡介 | bool $short 是否簡單的 | string 簡介 |public | | addUsage($usage) | 添加用法介紹 | string $usage | Command |public | | getUsages() | 獲取用法介紹 | void | array |public | ### **示例:** ~~~php <?php namespace app\common\command; use think\Console; use think\console\{Command,Output,Input}; use think\console\Input\{Argument,Option}; /* * 帶參數腳本兼容linux定時和手動執行 */ class Test extends Command { //定義任務名和描述 protected function configure(){ //設置參數 $this->addArgument('id',Argument::REQUIRED,'ID必填'); //必傳參數 $this->addArgument('name', Argument::OPTIONAL,'NAME選填');//可選參數 //選項定義 $this->addOption('type', 't', Option::VALUE_REQUIRED,'TYPE必填',0); //選項值必填 $this->addOption('status', 's', Option::VALUE_OPTIONAL,'STATUS選填',1); //選項值選填 $this->setName('test')->setDescription("php think test 測試"); //選項定義 } //調用該類時,會自動運行execute方法 protected function execute(Input $input, Output $output){ set_time_limit(0); @ob_end_clean(); @ob_implicit_flush(1); ini_set('memory_limit','100M'); # echo substr_replace('18858281234','****',3,4); header("Content-type: text/html; charset=utf-8"); date_default_timezone_set('Asia/Shanghai'); $excel_id = Cache::get('excel_id'); if(!empty($excel_id)){ //如果緩存有值,用定時腳本執行 $id = $excel_id; }else{//如果使用命令行手動傳參執行 $args = $input->getArguments();//獲取傳參數組 print_r($args); $options = $input->getOptions(); //獲取選項數組 print_r($options); $output->writeln("參數接收為:".$args['id'].'--'.$args['name']); //接收用全稱name,不能簡寫shortcut $output->writeln("選項接收為:".$options['type'].'--'.$options['status']); } $page = 0; while(true){ $page++; $res = $model->where(['id'=>$id])->paginate(100, false, [ 'page' => $page, 'query' => $query ]); //獲取訂單數據 $res = json_decode($res,true); if( empty($res['data']['body'])){//分頁獲取數據為空,則說明執行完畢 exit("已同步完成\n\r");//退出 } //數據不為空,循環遍歷插入本地數據庫 foreach($res['data']['body'] as $k=>$v){ $data['product_id'] = $v['product_id']; $data['order_status'] = $status; Db::table(Config('database.prefix').'table')->insert($data); } echo "同步第{$page}頁完成\n\r"; //輸出 } } } ~~~ ### **調用:** #### 控制臺調用 ~~~dart # 四種調用結果相同 [root@root root]# php think test 1 admin --type "2" --status "3" [root@root root]# php think test --type "2" --status "3" 1 admin [root@root root]# php think test 1 admin -t"2" -s"3" [root@root root]# php think test -t"2" -s"3" 1 admin Array ( [command] => test [id] => 1 [name] => admin ) Array ( [type] => 2 [status] => 3 [help] => [version] => [quiet] => [verbose] => [ansi] => [no-ansi] => [no-interaction] => ) 參數接收為:1--admin 選項接收為:2--3 [root@root root]# ~~~ #### 代碼調用 ~~~php namespace app\index\controller; use think\Console;//引入Console class Index{ $output = Console::call('command');#無參數調用 $output = Console::call('command',[args1,args2,argsN...]);#帶參數調用命令 $output = Console::call('test',['1','admin','-t2','-s3']);#帶參數調用(options和arguments不區分順序) return $output->fetch(); #獲取輸出信息 } ~~~ ## **Console** ### **方法** | 屬性名 | 描述 |參數說明|返回值|權限| | --- | --- | --- | --- | --- | | __construct($name = 'UNKNOWN', $version = 'UNKNOWN', $user = null) | | | | | | setUser($user) | 設置執行用戶 | $user | void | public | | init($run = true) | 初始化 Console | bool $run 是否運行 Console | int|Console |public、static| | call($command, array $parameters = [], $driver = 'buffer') | 調用命令 | string $command<br>array $parameters<br>string $driver | Output |public、static| | run() | 執行當前的指令 | void | int |public| | doRun(Input $input, Output $output) | 執行指令 | Input $input 輸入<br>Output $output 輸出 | int |public| | setDefinition(InputDefinition $definition) | 設置輸入參數定義 | InputDefinition $definition 輸入定義 | Console |public| | getDefinition() | 獲取輸入參數定義 | void | InputDefinition |public| | getHelp() | 獲取幫助信息 | void | string |public| | setCatchExceptions($boolean) | 設置是否捕獲異常 | bool $boolean 是否捕獲 |Console|public| | setAutoExit($boolean) | 設置是否自動退出 | bool $boolean 是否自動退出 | Console |public| | getName() | 獲取名稱 | void | string |public| | setName($name) | 設置名稱 | string $name 名稱 |Console|public| | getVersion() | 獲取版本 | void | string |public| | setVersion($version) | 設置版本 | string $version 版本信息 |Console |public| | getLongVersion() | 獲取完整的版本號 | void | string |public| | register($name) | 注冊一個指令 | string $name 指令名稱 | Command |public| | addCommands(array $commands) | 批量添加指令 | Command[] $commands 指令實例 |Console|public| | add(Command $command) | 添加一個指令 | Command $command 命令實例 | Command\|bool |public| | get($name) | 獲取指令 | string $name 指令名稱 | Command |public| | has($name) | 某個指令是否存在 | string $name 指令名稱 | bool |public| | getNamespaces() | 獲取所有的命名空間 | void | array |public| | findNamespace($namespace) | 查找注冊命名空間中的名稱或縮寫 | string $namespace | string |public| | find($name) | 查找指令 | string $name 名稱或者別名 | Command |public| | all($namespace = null) | 獲取所有的指令 | string $namespace 命名空間 | Command[] |public| | getAbbreviations($names) | 獲取可能的指令名 | array $names 指令名 | array |public| | configureIO(Input $input, Output $output) | 配置基于用戶的參數和選項的輸入和輸出實例 | Input $input 輸入實例<br>Output $output 輸出實例 | void |public,protected| | doRunCommand(Command $command, Input $input, Output $output) | 執行指令 | Command $command 指令實例<br>Input $input 輸入實例<br>Output $output 輸出實例| int |public,protected| | getCommandName(Input $input) | 獲取指令的名稱 | Input $input 輸入實例 | string |public,protected| | etDefaultInputDefinition() | 獲取默認輸入定義 | void | InputDefinition |public,protected| | getDefaultCommands() | 獲取默認命令 | void | Command[] |public,protected| | addDefaultCommands(array $classes) | 添加默認指令 | array $classes 指令 | void |public,static| | extractNamespace($name, $limit = null) | 返回指令的命名空間部分 | string $name 指令名稱<br>string $limit 部分的命名空間的最大數量 | string |public| | setDefaultCommand($commandName) | 設置默認的指令 | string $commandName 指令名稱 | Console |public| ## **Output** ### **常量** | 常量名 | 描述 |參數類型|默認值| | --- | --- | --- | --- | | VERBOSITY_QUIET | | | 0 | | VERBOSITY_NORMAL | | | 1 | | VERBOSITY_VERBOSE | | | 2 | | VERBOSITY_VERY_VERBOSE | | | 3 | | VERBOSITY_DEBUG | | | 4 | | OUTPUT_NORMAL | | | 0 | | OUTPUT_RAW | | | 1 | | OUTPUT_PLAIN | | | 2 | ### **方法** 實例化時傳入的think\console\output\driver\里的類(默認Console) 存入handle屬性,這里的方法差不多都是操作傳入的類的方法 | 屬性名 | 描述 |參數說明|返回值|權限| | --- | --- | --- | --- | --- | | __construct($driver = 'console') | | | |public| | ask(Input $input, $question, $default = null, $validator = null) | | | |public| | askHidden(Input $input, $question, $validator = null) | | | |public| | confirm(Input $input, $question, $default = true) | | | |public| | choice(Input $input, $question, array $choices, $default = null) | 窗口輸出時需要接受手動輸入值,如:$res=$output->choice($input,"請選擇正確答案",[1,2,3,4]); if($res==2){$output->write("恭喜你,回答正確!!!");}<br>![](https://img.kancloud.cn/a4/49/a449bd1fa458d2a221a203c1c7c7c3e7_301x228.png) | | |public| | askQuestion(Input $input, Question $question) | | | |public,protected| | block($style, $message) | 調用的是進一步封裝的newLine方法 | | |public,protected| | newLine($count = 1) | 輸出空行,調用的是進一步封裝的write方法 | int $count | |public| | writeln($messages, $type = self::OUTPUT_NORMAL) | 輸出信息并換行,調用的是進一步封裝的write方法 | string $messages<br>int $type | |public| | write($messages, $newline = false, $type = self::OUTPUT_NORMAL) | 輸出信息 | string $messages<br>bool $newline<br>int $type | |public| | renderException(\Exception $e) | | | |public| | setVerbosity($level) | | | |public| | getVerbosity() | | | |public| | isQuiet() | | | |public| | isVerbose() | | | |public| | isVeryVerbose() | | | |public| | isDebug() | | | |public| | describe($object, array $options = []) | | | |public| | __call($method, $args) | | | |public|
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看