/** * @param ClassDeclaration $declaration */ protected function writeDeclaration(ClassDeclaration $declaration) { $filename = $this->config->elementFilename(static::ELEMENT, $this->argument('name')); $filename = $this->files->normalizePath($filename); if ($this->files->exists($filename)) { $this->writeln("<fg=red>Unable to write '<comment>{$declaration->getName()}</comment>' declaration, " . "file '<comment>{$filename}</comment>' already exists.</fg=red>"); return; } $file = new FileDeclaration($this->elementNamespace(), $this->config->headerLines()); $file->addElement($declaration); $this->files->write($filename, $file->render(), FilesInterface::READONLY, true); $this->writeln("Declaration of '<info>{$declaration->getName()}</info>' " . "has been successfully written into '<comment>{$filename}</comment>'."); }
/** * @param Migrator $migrator * @throws ScaffolderException */ public function perform(Migrator $migrator) { /** * @var MigrationDeclaration $declaration */ $declaration = $this->createDeclaration(); if (!empty($this->option('table'))) { $columns = []; foreach ($this->option('column') as $field) { if (strpos($field, ':') === false) { throw new ScaffolderException("Column definition must in 'name:type' form."); } list($name, $type) = explode(':', $field); $columns[$name] = $type; } $declaration->declareCreation($this->option('table'), $columns); } $file = new FileDeclaration($this->elementNamespace(), $this->config->headerLines()); $file->addElement($declaration); $filename = $migrator->getRepository()->registerMigration($this->argument('name'), $declaration->getName(), $file->render()); $this->writeln("Declaration of '<info>{$declaration->getName()}</info>' " . "has been successfully written into '<comment>{$filename}</comment>'."); }