/**
  * @inheritdoc
  */
 public function doFetchAll()
 {
     $versions = new Linked();
     $classes = $this->scanner->getClasses(true);
     foreach ($classes as $class) {
         /* @var DerivedClassScanner $class */
         $className = $class->getName();
         $matches = [];
         if (preg_match($this->pattern, $className, $matches) && isset($matches[1]) && $class->isInstantiable()) {
             $migration = $this->getMigrationFactory()->create($className);
             if ($migration instanceof MigrationInterface) {
                 $id = hash('sha1', $className);
                 $version = new LinkedVersion($id, false, $migration);
                 $versions->add($version);
             }
         }
     }
     return $versions;
 }
Esempio n. 2
0
 /**
  * Executes migrations against a collection
  *
  * @param VersionInterface $goal
  * @param OptionsInterface $options
  * @param Linked $collection
  *
  * @return Linked
  *
  * @throws InvalidArgumentException
  */
 protected function runCollection(VersionInterface $goal, OptionsInterface $options, Linked $collection)
 {
     $current = 1;
     $progress = new Progress(max($collection->count(), 1), $current);
     // dispatch COLLECTION_BEFORE
     $this->getEmitter()->dispatchCollectionBefore($goal, $options, $collection, $progress);
     $modified = new Linked();
     $comparator = $collection->getComparator();
     // IMPROVE: add tests to see if rewind is necessary
     $collection->first();
     // rewind
     foreach ($collection as $version) {
         $progress->setCurrent($current);
         $result = $this->runSingle($version, $options, $progress);
         if ($result) {
             $modified->add($version);
         }
         if ($comparator($version, $goal) >= 0) {
             break;
         }
         $current += 1;
     }
     // dispatch COLLECTION_AFTER
     $this->getEmitter()->dispatchCollectionAfter($goal, $options, $modified, $progress);
     return $modified;
 }