summaryrefslogtreecommitdiff
path: root/src/Message/Handler.php
diff options
context:
space:
mode:
authorFbenas <philbeansburton@gmail.com>2017-03-12 04:02:03 +0000
committerFbenas <philbeansburton@gmail.com>2017-03-12 04:02:03 +0000
commit755248886ad294bade86cb8a5ce36465b5193f36 (patch)
treed7a55ad3b1913b2a71e3616a3b14693268b10b22 /src/Message/Handler.php
parent1eeeb808275e6e0bcff6ed0c2e7b109d81da67e7 (diff)
Inital commit, created message handler
Diffstat (limited to 'src/Message/Handler.php')
-rw-r--r--src/Message/Handler.php69
1 files changed, 69 insertions, 0 deletions
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 @@
+<?php
+
+namespace App\Message;
+
+use App\Message\Overview;
+
+/**
+* Handles messages and context
+*/
+class Handler
+{
+ protected $important = [];
+
+ protected $importantValues = [];
+
+ public function __construct($important)
+ {
+ $this->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