From 6f4cd9178ba55ffb3fd80816cf9f4cda39ee0cad Mon Sep 17 00:00:00 2001 From: Fbenas Date: Sun, 12 Mar 2017 17:46:18 +0000 Subject: Doc block and PSR --- src/Message/Base.php | 83 ++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 74 insertions(+), 9 deletions(-) (limited to 'src/Message/Base.php') 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 */ 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 + */ 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 + */ public function __construct() { $this->loadConfig(); - + $this->loadMessage(); } + /** + * Render the message, injecting any values into the message using mustache + * + * @author Phil Burton + */ public function renderMessage() { $m = new Mustache_Engine; return $m->render($this->message, $this->getInjectValues()); } + + /** + * Return the injected values + * + * @author Phil Burton + */ 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 + */ 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 + */ public function setFromArray(array $array) { foreach ($array as $key => $value) { @@ -78,4 +143,4 @@ class Base } } } -} \ No newline at end of file +} -- cgit v1.2.3