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.php83
1 files changed, 74 insertions, 9 deletions
diff --git a/src/Message/Base.php b/src/Message/Base.php
index 4565de9..2b7b0e4 100644
--- a/src/Message/Base.php
+++ b/src/Message/Base.php
@@ -8,15 +8,51 @@ use App\Message\Handler;
/**
* Base class for a message
+*
+* @author Phil Burton <phil@pgburton.com>
*/
class Base
{
+ /**
+ * Message name to load
+ *
+ * @var string
+ */
protected $message_name;
+
+ /**
+ * Cache of the loaded config array
+ *
+ * @var string
+ */
protected $config;
+
+ /**
+ * The raw message string loaded from config
+ *
+ * @var string
+ */
protected $message;
+
+ /**
+ * The list of vars we need to inject
+ *
+ * @var array
+ */
protected $injects = [];
+
+ /**
+ * The array of important vars
+ *
+ * @var string
+ */
protected $important;
+ /**
+ * Load the message from the config
+ *
+ * @author Phil Burton <phil@pgburton.com>
+ */
protected function loadMessage()
{
if (!array_key_exists($this->message_name, $this->config)) {
@@ -26,6 +62,9 @@ class Base
$this->message = $this->config[$this->message_name];
}
+ /**
+ * Load the config
+ */
protected function loadConfig()
{
$config =Config::getConfig();
@@ -37,39 +76,65 @@ class Base
$this->config = $config;
}
+ /**
+ * Construct, load config and message
+ *
+ * @author Phil Burton <phil@pgburton.com>
+ */
public function __construct()
{
$this->loadConfig();
-
+
$this->loadMessage();
}
+ /**
+ * Render the message, injecting any values into the message using mustache
+ *
+ * @author Phil Burton <phil@pgburton.com>
+ */
public function renderMessage()
{
$m = new Mustache_Engine;
return $m->render($this->message, $this->getInjectValues());
}
+
+ /**
+ * Return the injected values
+ *
+ * @author Phil Burton <phil@pgburton.com>
+ */
public function getInjectValues()
{
$out = [];
- foreach ($this->injects as $inject) {
- $out[$inject] = $this->$inject;
- }
+ foreach ($this->injects as $inject) {
+ $out[$inject] = $this->$inject;
+ }
return $out;
}
+ /**
+ * Get the important injected values
+ *
+ * @author Phil Burton <phil@pgburton.com>
+ */
public function getImportantValues()
{
- $out = [];
- foreach ($this->important as $important) {
- $out[$important] = $this->$important;
- }
+ $out = [];
+ foreach ($this->important as $important) {
+ $out[$important] = $this->$important;
+ }
return $out;
}
+ /**
+ * Set-up this message's inject values based on an input array
+ *
+ * @author Phil Burton <phil@pgburton.com>
+ */
public function setFromArray(array $array)
{
foreach ($array as $key => $value) {
@@ -78,4 +143,4 @@ class Base
}
}
}
-} \ No newline at end of file
+}