backup = BackupFactory::build($scenario['backup']); $this->transport = TransportFactory::build($this->backup, $scenario['transport']); } public function send() { try { $this->transport->send(); } catch (\Exception $e) { throw $e; } } /** * Launch the whole job * * @param $scenario * * @throws \Exception */ public static function launch($scenario) { // add autoloader static::register(); $scenario = __DIR__.'/../scenario/'.$scenario; // check the given scenario if (is_readable($scenario)) { $scenario = json_decode(file_get_contents($scenario), true); if (!is_null($scenario) && static::isValid($scenario)) { try { $scenario = new self($scenario); $scenario->send(); } catch (\Exception $e) { throw $e; } exit; } throw new \Exception('invalid scenario.'); } throw new \Exception('scenario not found.'); } /** * Check given scenario validation * * @param array $scenario * * @return bool */ public static function isValid(array $scenario) { return isset($scenario['backup']) && count($scenario['backup']) === 1 && isset($scenario['transport']) && count($scenario['transport']) === 1; } }