From c593f323781d98e88f810ceb0c5ac7323c5170cc Mon Sep 17 00:00:00 2001 From: Shikiryu Date: Fri, 10 Jul 2015 19:07:14 +0200 Subject: [PATCH] Going namespaced, going scenario style --- Transport/Factory.php | 20 --------- app/code/Scenario.php | 44 +++++++++++++++++++ .../code/Transport}/Abstract.php | 8 +++- {Transport => app/code/Transport}/Email.php | 4 +- {Transport => app/code/Transport}/FTP.php | 3 +- app/code/Transport/Factory.php | 22 ++++++++++ Abstract.php => app/code/backup/Abstract.php | 5 +-- app/code/backup/Factory.php | 20 +++++++++ Files.php => app/code/backup/Files.php | 4 +- Mysql.php => app/code/backup/Mysql.php | 4 +- app/scenario/scenarii.json | 31 +++++++++++++ app/temp/.gitkeep | 0 12 files changed, 134 insertions(+), 31 deletions(-) delete mode 100644 Transport/Factory.php create mode 100644 app/code/Scenario.php rename {Transport => app/code/Transport}/Abstract.php (72%) rename {Transport => app/code/Transport}/Email.php (99%) rename {Transport => app/code/Transport}/FTP.php (96%) create mode 100644 app/code/Transport/Factory.php rename Abstract.php => app/code/backup/Abstract.php (96%) create mode 100644 app/code/backup/Factory.php rename Files.php => app/code/backup/Files.php (87%) rename Mysql.php => app/code/backup/Mysql.php (96%) create mode 100644 app/scenario/scenarii.json create mode 100644 app/temp/.gitkeep diff --git a/Transport/Factory.php b/Transport/Factory.php deleted file mode 100644 index b1cd561..0000000 --- a/Transport/Factory.php +++ /dev/null @@ -1,20 +0,0 @@ -send(); - } - return false; - } -} \ No newline at end of file diff --git a/app/code/Scenario.php b/app/code/Scenario.php new file mode 100644 index 0000000..063825e --- /dev/null +++ b/app/code/Scenario.php @@ -0,0 +1,44 @@ +backup = BackupFactory::build($scenario['backup']); + $this->to = TransportFactory::build($scenario['to']); + } + + + public static function launch($scenario) + { + if (is_readable($scenario)) { + $scenario = json_decode(file_get_contents($scenario), true); + if (static::isValid($scenario)) { + $scenario = new self($scenario); + } + throw new \Exception('invalid scenario.'); + } + throw new \Exception('scenario not found.'); + } + + public static function isValid(\StdClass $scenario) + { + return + isset($scenario->backup) && + count($scenario->backup) === 1 && + isset($scenario->to) && + count($scenario->to) === 1; + } + +} \ No newline at end of file diff --git a/Transport/Abstract.php b/app/code/Transport/Abstract.php similarity index 72% rename from Transport/Abstract.php rename to app/code/Transport/Abstract.php index 86277e5..45c3100 100644 --- a/Transport/Abstract.php +++ b/app/code/Transport/Abstract.php @@ -1,12 +1,16 @@ from@example.net", + "encoding" : "UTF-8", + "subject" : "[Example.net] backup of the day", + "message" : "Hi,\n\nYou can find your backup in this mail.\n\nRegards,\nMyself." + }, + "Ftp": { + "host" : "ftp.domain.com", + "login" : "login", + "password" : "password", + "folder" : "/folder" + } + } +}] \ No newline at end of file diff --git a/app/temp/.gitkeep b/app/temp/.gitkeep new file mode 100644 index 0000000..e69de29