/** * @param string $name * @return string */ public function create($name) { $fileName = date('ymd_His_') . $name . '.php'; $filePath = $this->config->getPath() . '/' . $fileName; if (file_exists($filePath) || !is_dir($this->config->getPath())) { throw new InvalidArgumentException(sprintf('cannot write the file at %s.', $filePath)); } $contents = $this->template->getContext($name); file_put_contents($filePath, $contents); return $filePath; }
/** * @return array */ protected function getAllMigrationFiles() { $files = []; foreach (new DirectoryIterator($this->config->getPath()) as $file) { if ($file->isDot() || $file->isDir() || $file->getFilename()[0] === '.') { continue; } $files[] = $file->getFileInfo(); } usort($files, function (SplFileInfo $file, SplFileInfo $nextFile) { if ($file->getFilename() > $nextFile->getFilename()) { return 1; } return $file->getFilename() < $nextFile->getFilename() ? -1 : 0; }); return $files; }