summaryrefslogtreecommitdiff
path: root/src/Message/Base.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/Message/Base.php')
-rw-r--r--src/Message/Base.php46
1 files changed, 29 insertions, 17 deletions
diff --git a/src/Message/Base.php b/src/Message/Base.php
index 2b7b0e4..b6c1c8e 100644
--- a/src/Message/Base.php
+++ b/src/Message/Base.php
@@ -5,6 +5,7 @@ namespace App\Message;
use Mustache_Engine;
use App\Config\Config;
use App\Message\Handler;
+use Exception;
/**
* Base class for a message
@@ -14,13 +15,6 @@ use App\Message\Handler;
class Base
{
/**
- * Message name to load
- *
- * @var string
- */
- protected $message_name;
-
- /**
* Cache of the loaded config array
*
* @var string
@@ -55,11 +49,11 @@ class Base
*/
protected function loadMessage()
{
- if (!array_key_exists($this->message_name, $this->config)) {
- throw new Exception('Could not load messge from config (' . $this->message_name . ')');
+ if (!array_key_exists($this->getName(), $this->config)) {
+ throw new Exception('Could not load messge from config (' . $this->getName() . ')');
}
- $this->message = $this->config[$this->message_name];
+ $this->message = $this->config[$this->getName()];
}
/**
@@ -67,25 +61,39 @@ class Base
*/
protected function loadConfig()
{
- $config =Config::getConfig();
+ $config = Config::getConfig();
if (!$config) {
- throw new \Exception('Could not load config');
+ throw new Exception('Could not load config');
}
$this->config = $config;
}
/**
+ * Get the name for this message, by default we use the class name
+ *
+ * @author Phil Burton <phil@pgburton.com>
+ * @return string
+ */
+ public function getName()
+ {
+ $split = explode("\\", get_class($this));
+ return strtolower($split[count($split) - 1]);
+ }
+
+ /**
* Construct, load config and message
*
* @author Phil Burton <phil@pgburton.com>
*/
- public function __construct()
+ public function __construct(Handler $handler)
{
$this->loadConfig();
$this->loadMessage();
+
+ $this->setFromHandler($handler);
}
/**
@@ -135,11 +143,15 @@ class Base
*
* @author Phil Burton <phil@pgburton.com>
*/
- public function setFromArray(array $array)
+ public function setFromHandler(Handler $handler)
{
- foreach ($array as $key => $value) {
- if (in_array($key, $this->injects)) {
- $this->$key = (string) $value;
+ foreach ($handler->returnImportants() as $name) {
+ if (in_array($name, $this->injects)) {
+ $value = $handler->$name;
+
+ if (isset($value) && $value) {
+ $this->$name = $value;
+ }
}
}
}