backup = BackupFactory::build($scenario['backup']); $this->transport = TransportFactory::build($this->backup, $scenario['transport']); } /** * check if backup is valid and then launch the transfer * * @return bool * @throws BackupException * @see BackupAbstract::isValid * @see TransportAbstract::send * */ public function send(): bool { if ($this->backup->isValid()) { return $this->transport->send(); } throw new BackupException('Backup configuration is invalid.'); } /** * Launch the whole job * * @param $scenario * * @return bool * @throws BackupException * @throws ComposerNotFoundException * @throws ScenarioException * @throws ScenarioNotFoundException */ public static function launch($scenario): bool { // add autoloader static::register(); // check the given scenario if (is_readable($scenario)) { $scenario = json_decode(file_get_contents($scenario), true); if ($scenario !== null && static::isValid($scenario)) { try { $scenario = new self($scenario); return $scenario->send(); } catch (BackupException $e) { throw $e; } } throw new ScenarioException('invalid scenario.'); } throw new ScenarioNotFoundException(sprintf('scenario «%s» not found.', $scenario)); } /** * Check given scenario validation * * @param array $scenario * * @return bool */ public static function isValid(array $scenario): bool { return isset($scenario['backup'], $scenario['transport']) && count($scenario['backup']) === 1 && count($scenario['transport']) === 1; } }