addArgument('file', InputArgument::OPTIONAL, '文件路径及其名称'); $this->addOption('file', 'file', InputOption::VALUE_REQUIRED, '要解析的文件名称'); } /** * @param InputInterface $input * @param OutputInterface $output * @return int */ protected function execute(InputInterface $input, OutputInterface $output) { $file = $input->getOption('file'); $fileData = function($file) { $content = fopen($file, 'r'); //if (!$file) die('file does not exist or cannot be opened'); while (($line = fgets($content)) !== false) { yield $line; } fclose($content); }; foreach ($fileData($file) as $line) { $line = explode(": ", $line); $paramsc = $line[count($line)-1]; $params = json_decode($paramsc,true); if (!is_array($params)) { $output->writeln('不是json:'.$params); } $res = TrackService::confirm($params); if (!$res) { continue; } TrackService::push($params,1); } return 1; } }