addArgument('name', InputArgument::REQUIRED, 'Bootstrap name'); $this->addArgument('enable', InputArgument::OPTIONAL, 'Enable or not'); } /** * @param InputInterface $input * @param OutputInterface $output * @return int */ protected function execute(InputInterface $input, OutputInterface $output): int { $name = $input->getArgument('name'); $enable = in_array($input->getArgument('enable'), ['no', '0', 'false', 'n']) ? false : true; $output->writeln("Make bootstrap $name"); $name = str_replace('\\', '/', $name); if (!$bootstrap_str = Util::guessPath(app_path(), 'bootstrap')) { $bootstrap_str = Util::guessPath(app_path(), 'controller') === 'Controller' ? 'Bootstrap' : 'bootstrap'; } $upper = $bootstrap_str === 'Bootstrap'; if (!($pos = strrpos($name, '/'))) { $name = ucfirst($name); $file = app_path() . "/$bootstrap_str/$name.php"; $namespace = $upper ? 'App\Bootstrap' : 'app\bootstrap'; } else { if($real_name = Util::guessPath(app_path(), $name)) { $name = $real_name; } if ($upper && !$real_name) { $name = preg_replace_callback('/\/([a-z])/', function ($matches) { return '/' . strtoupper($matches[1]); }, ucfirst($name)); } $path = "$bootstrap_str/" . substr($upper ? ucfirst($name) : $name, 0, $pos); $name = ucfirst(substr($name, $pos + 1)); $file = app_path() . "/$path/$name.php"; $namespace = str_replace('/', '\\', ($upper ? 'App/' : 'app/') . $path); } $this->createBootstrap($name, $namespace, $file); if ($enable) { $this->addConfig("$namespace\\$name", config_path() . '/bootstrap.php'); } return self::SUCCESS; } /** * @param $name * @param $namespace * @param $file * @return void */ protected function createBootstrap($name, $namespace, $file) { $path = pathinfo($file, PATHINFO_DIRNAME); if (!is_dir($path)) { mkdir($path, 0777, true); } $bootstrap_content = <<