Пример #1
0
 /**
  * Returns true if the specified version is valid (can be added) to the collection. Otherwise, it MUST throw
  * an exception.
  *
  * @param DeltaInterface $version
  *
  * @return bool
  *
  * @throws CollectionException
  */
 public function validate(DeltaInterface $version)
 {
     if (!$version->isMigrated()) {
         throw new CollectionException('Invalid version specified: this collection only accepts deltas that are migrated.');
     }
     return parent::validate($version);
 }
 /**
  * {@inheritdoc}
  *
  * Given the following $namespaces passed in the constructor:
  *   - Taz (lowest priority)
  *   - Bar
  *   - Foo (highest priority)
  *
  * Will produce the following results based on the migration's FQCN:
  *   - (Foo\v200012, Bar\v201612) => -1
  *   - (Taz\v201612, Foo\v200012) => 1
  *   - (FooBar\v201612, Taz\v200012) => 1
  *   - (Taz\v201612, Taz\v201601) => delegate to fallback
  *   - (FooBar\v201612, FooBar\v200012) => delegate to fallback
  *
  * @param DeltaInterface $version1
  * @param DeltaInterface $version2
  *
  * @return int
  *
  * @throws InvalidArgumentException
  */
 public function compare(DeltaInterface $version1, DeltaInterface $version2)
 {
     $class1 = $version1->getMigrationClassName();
     $class2 = $version2->getMigrationClassName();
     if ($class1 === $class2) {
         // exit early in this case
         return 0;
     }
     $res = $this->compareNamespaces($class1, $class2);
     // null = could not determine order | zero = both orders are equal
     if (empty($res)) {
         // delegate sorting to the fallback comparator
         $res = call_user_func($this->fallbackComparator, $version1, $version2);
     }
     return $res;
 }
Пример #3
0
 /**
  * @inheritdoc
  */
 public function compare(DeltaInterface $version1, DeltaInterface $version2)
 {
     return strcmp($version1->getId(), $version2->getId());
 }
Пример #4
0
 /**
  * @inheritdoc
  */
 public function delete(DeltaInterface $version)
 {
     return $this->mapper->delete($version->getId());
 }
Пример #5
0
 /**
  * @inheritdoc
  */
 public function compare(DeltaInterface $version1, DeltaInterface $version2)
 {
     return strcmp($version1->getMigrationClassName(), $version2->getMigrationClassName());
 }
Пример #6
0
 /**
  * @inheritdoc
  */
 public function validate(DeltaInterface $version)
 {
     return !empty($version->getId());
     // basically: any DeltaInterface is valid for this collection
 }
Пример #7
0
 /**
  * {@inheritDoc}
  */
 public function add(DeltaInterface $value)
 {
     $key = $value->getId()->toString();
     if ($this->contains($key)) {
         throw new AlreadyExistsException(sprintf('Element with key "%s" already exists. Remove it first or use replace() if you want to overwrite it.', $key));
     }
     $this->elements[$key] = $value;
     return true;
 }
Пример #8
0
 /**
  * Returns true if the operation is forced, or if the direction is the opposite to the state of the migration.
  *
  * @param DeltaInterface $version
  * @param OptionsInterface $options
  *
  * @return bool
  */
 protected function shouldMigrate(DeltaInterface $version, OptionsInterface $options)
 {
     return $options->isForced() || $options->getDirection()->isUp() ^ $version->isMigrated();
     // direction is opposite to state
 }