/** * Create migrator. */ protected function createMigrator($database, $files) { $config = ['table' => 'migrations', 'dir' => 'migrations']; $templatesCollection = new TemplatesCollection($config); $templatesCollection->registerBasicTemplates(); return new Migrator($config, $templatesCollection, $database, $files); }
/** * Initialize autocreation. * * @param string $dir * @param string|null $table */ public static function init($dir, $table = null) { $templates = new TemplatesCollection(); $templates->registerAutoTemplates(); $config = ['dir' => $dir, 'table' => is_null($table) ? 'migrations' : $table]; static::$migrator = new Migrator($config, $templates); static::addEventHandlers(); static::turnOn(); }
/** * Create migration file. * * @param string $name - migration name * @param string $templateName * @param array $replace - array of placeholders that should be replaced with a given values. * * @return string */ public function createMigration($name, $templateName, array $replace = []) { $this->files->createDirIfItDoesNotExist($this->dir); $fileName = $this->constructFileName($name); $className = $this->getMigrationClassNameByFileName($fileName); $templateName = $this->templates->selectTemplate($templateName); $template = $this->files->getContent($this->templates->getTemplatePath($templateName)); $template = $this->replacePlaceholdersInTemplate($template, array_merge($replace, ['className' => $className])); $this->files->putContent($this->dir . '/' . $fileName . '.php', $template); return $fileName; }
/** * Collect and return templates from a Migrator. * * @return array */ protected function collectRows() { $rows = collect($this->collection->all())->filter(function ($template) { return $template['is_alias'] == false; })->sortBy('name')->map(function ($template) { $row = []; $names = array_merge([$template['name']], $template['aliases']); $row[] = implode("\n/ ", $names); $row[] = wordwrap($template['path'], 65, "\n", true); $row[] = wordwrap($template['description'], 25, "\n", true); return $row; }); return $this->separateRows($rows); }