From 755248886ad294bade86cb8a5ce36465b5193f36 Mon Sep 17 00:00:00 2001 From: Fbenas Date: Sun, 12 Mar 2017 04:02:03 +0000 Subject: Inital commit, created message handler --- src/Message/Base.php | 72 ++++++++++++++++++++++++++++++++++++++++++++++++ src/Message/Handler.php | 69 ++++++++++++++++++++++++++++++++++++++++++++++ src/Message/Overview.php | 25 +++++++++++++++++ 3 files changed, 166 insertions(+) create mode 100644 src/Message/Base.php create mode 100644 src/Message/Handler.php create mode 100644 src/Message/Overview.php (limited to 'src/Message') diff --git a/src/Message/Base.php b/src/Message/Base.php new file mode 100644 index 0000000..a4430da --- /dev/null +++ b/src/Message/Base.php @@ -0,0 +1,72 @@ +message_name, $this->config)) { + throw new Exception('Could not load messge from config (' . $this->message_name . ')'); + } + + $this->message = $this->config[$this->message_name]; + } + + protected function loadConfig() + { + $config =Config::getConfig(); + + if (!$config) { + throw new \Exception('Could not load config'); + } + + $this->config = $config; + } + + public function __construct() + { + $this->loadConfig(); + + $this->loadMessage(); + } + + public function renderMessage() + { + $m = new Mustache_Engine; + return $m->render($this->message, $this->getInjectValues()); + } + + public function getInjectValues() + { + $out = []; + foreach ($this->injects as $inject) { + $out[$inject] = $this->$inject; + } + + return $out; + } + + public function getImportantValues() + { + $out = []; + foreach ($this->important as $important) { + $out[$important] = $this->$important; + } + + return $out; + } +} \ No newline at end of file diff --git a/src/Message/Handler.php b/src/Message/Handler.php new file mode 100644 index 0000000..8729c1a --- /dev/null +++ b/src/Message/Handler.php @@ -0,0 +1,69 @@ +setupImportant($important); + } + /** + * Set's up important attributes on this class + */ + public function setupImportant($important = []) + { + $this->important = $important; + } + + protected function setImportantValues($array) + { + foreach ($array as $name => $value) { + $this->addImportantValue($name, $value); + } + } + + protected function addImportantValue($name, $value) + { + if (in_array($name, $this->important)) { + $this->importantValues[$name] = $value; + } + + return $name; + } + + public function returnImportant($name) + { + if (!array_key_exists($name, $this->importantValues)) { + throw new \Exception('The var ' . $name . ' is not set in this context'); + } + + return $this->importantValues[$name]; + } + + public function __call($name, $arguments) + { + if (strpos($name, 'get') === 0) { + $this->returnImporant(substr($name, 3)); + } + } + + public function renderOpeningMessage() + { + $overview = new Overview(); + $message = $overview->renderMessage(); + + $this->setImportantValues($overview->getImportantValues()); + + return $message; + } +} \ No newline at end of file diff --git a/src/Message/Overview.php b/src/Message/Overview.php new file mode 100644 index 0000000..3676176 --- /dev/null +++ b/src/Message/Overview.php @@ -0,0 +1,25 @@ +inject = $this->getInject(); + parent::__construct(); + } + + public function getInject() + { + return 'foo'; + } +} \ No newline at end of file -- cgit v1.2.3