Пример #1
0
 public function getAll($all = false)
 {
     $classes = new ArrayIterator();
     $iterator = new GlobIterator(sprintf('%s/Version_*.php', $this->config->getDir()), FilesystemIterator::KEY_AS_FILENAME);
     foreach ($iterator as $item) {
         /** @var $item \SplFileInfo */
         if (preg_match('/(Version_(\\d+))\\.php/', $item->getFilename(), $matches)) {
             $applied = $this->versionTable->applied($matches[2]);
             if ($all || !$applied) {
                 $className = $this->config->getNamespace() . '\\' . $matches[1];
                 if (!class_exists($className)) {
                     /** @noinspection PhpIncludeInspection */
                     require_once $this->config->getDir() . '/' . $item->getFilename();
                 }
                 if (class_exists($className)) {
                     $reflectionClass = new ReflectionClass($className);
                     $reflectionDescription = new ReflectionProperty($className, 'description');
                     if ($reflectionClass->implementsInterface(MigrationInterface::class)) {
                         $classes->append(['version' => $matches[2], 'class' => $className, 'description' => $reflectionDescription->getValue(), 'applied' => $applied]);
                     }
                 }
             }
         }
     }
     $classes->uasort(function ($a, $b) {
         if ($a['version'] == $b['version']) {
             return 0;
         }
         return $a['version'] < $b['version'] ? -1 : 1;
     });
     return $classes;
 }
Пример #2
0
 public function testConfigDafaults()
 {
     $filesystem = $this->prophesize(Filesystem::class);
     $appConfig = ['migrations' => ['dir' => '/migrations', 'namespace' => 'T4web\\Migrations', 'show_log' => true]];
     $filesystem->isDir($appConfig['migrations']['dir'])->willReturn(true);
     $filesystem->isWritable($appConfig['migrations']['dir'])->willReturn(true);
     $config = new Config($appConfig, $filesystem->reveal());
     $this->assertEquals($appConfig['migrations']['dir'], $config->getDir());
     $this->assertEquals($appConfig['migrations']['namespace'], $config->getNamespace());
     $this->assertEquals('Zend\\Db\\Adapter\\Adapter', $config->getAdapter());
     $this->assertEquals($appConfig['migrations']['show_log'], $config->isShowLog());
 }
Пример #3
0
 /**
  * @param Config $config
  * @param Filesystem $filesystem
  * @throws \Exception
  */
 public function __construct(Config $config, Filesystem $filesystem)
 {
     $this->migrationsDir = $config->getDir();
     $this->migrationNamespace = $config->getNamespace();
     $this->filesystem = $filesystem;
 }