storageHandler = $storageHandler; } /** * @param ContextProviderInterface $contextProvider * @param string $label */ public function addProvider(ContextProviderInterface $contextProvider, $label) { $this->providers[$label] = $contextProvider; } /** * @param string $migrationName */ public function storeCurrentContext($migrationName) { $context = array(); foreach($this->providers as $label => $provider) { $context[$label] = $provider->getCurrentContext($migrationName); } $this->storageHandler->storeMigrationContext($migrationName, $context); } /** * @param string $migrationName * @throws \Exception */ public function restoreCurrentContext($migrationName) { $context = $this->storageHandler->loadMigrationContext($migrationName); if (!is_array($context)) { throw new \Exception("No execution context found associated with migration '$migrationName'"); } foreach($this->providers as $label => $provider) { if (isset($context[$label])) { $provider->restoreContext($migrationName, $context[$label]); } } } public function deleteContext($migrationName) { $this->storageHandler->deleteMigrationContext($migrationName); } }