public function execute(IOStream $io) { $fileType = $this->input('fileType'); $name = $this->input('name'); if (!$fileType || !$name) { $io->showErr("Please specify the 'fileType' and 'name' for the given file. See below help for details"); $this->showHelp($io); return; } $fileSystem = $this->application()->getFileSystem(); $real = $this->getRealFolder($this->application()->appPath(), $fileType, $io); $appFolder = $real['folder']; $namespace = $real['namespace']; $name = $this->formatName($name, $fileType); $replace = ['{{$namespace}}' => $namespace, '{{$fileName}}' => $name, '{{$className}}' => $name]; $stub = $fileSystem->getContents(__DIR__ . "/../Stubs/{$fileType}.stub"); $content = str_replace(array_keys($replace), array_values($replace), $stub); $filePath = rtrim($appFolder, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . $name . '.php'; if ($fileType === 'migration') { $migration = new Migration(['migration' => $name, 'batch' => 0]); $migration->save(); } if ($fileSystem->write($filePath, $content)) { $io->writeln($name . ' file created successfully', 'green'); } else { throw new \RuntimeException('Unable to create file ' . $filePath); } }
private function showStatus() { /** @var Migration[] $all */ $all = Migration::find(); foreach ($all as $i => $model) { $all[$i] = $model->toArray(); } $headers = ['id', 'migration', 'batch', 'created_at', 'modified_at']; array_unshift($all, $headers); $this->io->showTable($all); }