diff options
Diffstat (limited to 'src/Message/Base.php')
-rw-r--r-- | src/Message/Base.php | 72 |
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 |