/** * Validates the version is a LinkedVersion and returns the class name of its migration * * @param VersionInterface $version * * @return string * * @throws InvalidArgumentException */ protected final function getMigrationClass(VersionInterface $version) { if (!$version instanceof LinkedVersionInterface) { throw new InvalidArgumentException(sprintf("Expected version %s to be linked to a migration", $version->getId())); } return get_class($version->getMigration()); }
/** * Adds a new version to the collection if it doesn't exist or replaces it if it does. * * @param VersionInterface $version */ public function addOrReplace(VersionInterface $version) { $index = $this->indexOfId($version->getId()); if (null !== $index) { $this->remove($index); } $this->add($version); }
/** * The internal compare function. Should return less than zero (0), zero or greater than zero if the first item is * respectively less than, equal to, or greater than the second item. * * @param VersionInterface $version1 * @param VersionInterface $version2 * * @return mixed */ protected function compare(VersionInterface $version1, VersionInterface $version2) { return strcmp($version1->getId(), $version2->getId()); }
/** * @{inheritdoc} * @param VersionInterface $version * @return bool|int * @throws StorageException */ public function delete(VersionInterface $version) { $result = false; $stored = $this->fetchAll(); $element = $stored->getById($version->getId()); if ($element) { $stored->removeElement($element); $result = $this->saveCollection($stored); } return $result; }