Exemplo n.º 1
0
 public function __construct($appConfig, Filesystem $filesystem)
 {
     if (!isset($appConfig['migrations'])) {
         throw new RuntimeException("Missing migrations configuration");
     }
     $options = $appConfig['migrations'];
     if (!isset($options['dir'])) {
         throw new RuntimeException("`dir` has not be specified in migrations configuration");
     }
     $this->dir = $options['dir'];
     if (!isset($options['namespace'])) {
         throw new RuntimeException("`namespace` has not be specified in migrations configuration");
     }
     $this->namespace = $options['namespace'];
     if (!$filesystem->isDir($this->dir)) {
         $filesystem->mkdir($this->dir, 0775);
     } elseif (!$filesystem->isWritable($this->dir)) {
         throw new RuntimeException(sprintf('Migrations directory is not writable %s', $this->dir));
     }
     if (!isset($options['adapter'])) {
         $options['adapter'] = 'Zend\\Db\\Adapter\\Adapter';
     }
     $this->adapter = $options['adapter'];
     if (isset($options['show_log'])) {
         $this->showLog = $options['show_log'];
     }
 }
Exemplo n.º 2
0
 /**
  * Generate new migration skeleton class
  *
  * @return string path to new skeleton class file
  * @throws \Exception
  */
 public function generate()
 {
     $className = 'Version_' . date('YmdHis', time());
     $classPath = $this->migrationsDir . DIRECTORY_SEPARATOR . $className . '.php';
     if ($this->filesystem->exists($classPath)) {
         throw new RuntimeException(sprintf('Migration %s exists!', $className));
     }
     $this->filesystem->put($classPath, $this->getTemplate($className));
     return $classPath;
 }