protected function execute(InputInterface $input, OutputInterface $output) { $baseUrl = $input->getArgument('url'); $directoryList = []; $listDirectoryCommand = 'find ./src -type d |grep "Controller$"'; $listControllerCommand = 'find %s -maxdepth 1 -type f |grep "Controller.php$"'; $this->commandUtility = Factory::createNewObject(CommandUtility::class); $this->commandUtility->exec($listDirectoryCommand, $directoryList); foreach ($directoryList as $directory) { $controllerFileList = []; $this->commandUtility->exec(sprintf($listControllerCommand, $directory), $controllerFileList); foreach ($controllerFileList as $controllerFile) { $this->generateScript($input, $output, $controllerFile, $baseUrl); } } $this->writeCode($input, $output); }
/** * This method will run a find command and call the appropriate method to override the found classes * with a specified base class. * * @param string $findCommand * @param array $baseClassParts * @param string $searchPattern */ protected function replaceInFiles($findCommand, $searchPattern, $replace) { $fileList = []; $this->commandUtility->exec($findCommand, $fileList); $replaceCommand = "sed -i -e \"s/%s/%s/g\" %s"; foreach ($fileList as $file) { $command = sprintf($replaceCommand, $searchPattern, $replace, $file, $file); $this->commandUtility->exec($command); } }