summaryrefslogtreecommitdiff
path: root/src/Message/Base.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/Base.php
parent1eeeb808275e6e0bcff6ed0c2e7b109d81da67e7 (diff)
Inital commit, created message handler
Diffstat (limited to 'src/Message/Base.php')
-rw-r--r--src/Message/Base.php72
1 files changed, 72 insertions, 0 deletions
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 @@
+<?php
+
+namespace App\Message;
+
+use Mustache_Engine;
+use App\Config\Config;
+use App\Message\Handler;
+
+/**
+* Base class for a message
+*/
+class Base
+{
+ protected $message_name;
+ protected $config;
+ protected $message;
+ protected $injects = [];
+ protected $important;
+
+ protected function loadMessage()
+ {
+ if (!array_key_exists($this->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