summaryrefslogtreecommitdiff
path: root/src/Message/Handler.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/Message/Handler.php')
-rw-r--r--src/Message/Handler.php72
1 files changed, 64 insertions, 8 deletions
diff --git a/src/Message/Handler.php b/src/Message/Handler.php
index 89752c5..825ceda 100644
--- a/src/Message/Handler.php
+++ b/src/Message/Handler.php
@@ -6,25 +6,52 @@ use App\Message\Overview;
/**
* Handles messages and context
+*
+* @author Phil Burton <phil@pgburton.com>
*/
class Handler
{
+ /**
+ * The important set of injects for this handler
+ *
+ * @var string[]
+ */
protected $important = [];
+ /**
+ * The important set of values of injects for this handler
+ *
+ * @var mixed[]
+ */
protected $importantValues = [];
+ /**
+ * Construct our handler
+ *
+ * @author Phil Burton <phil@pgburton.com>
+ * @param string[] $important
+ */
public function __construct($important)
{
$this->setupImportant($important);
}
/**
- * Set's up important attributes on this class
+ * Set the important list
+ *
+ * @author Phil Burton <phil@pgburton.com>
+ * @param string[] $important
*/
public function setupImportant($important = [])
{
$this->important = $important;
}
+ /**
+ * Set important values
+ *
+ * @author Phil Burton <phil@pgburton.com>
+ * @param mixed[] $array
+ */
protected function setImportantValues($array)
{
foreach ($array as $name => $value) {
@@ -32,6 +59,13 @@ class Handler
}
}
+ /**
+ * Add an important value to our array
+ *
+ * @author Phil Burton <phil@pgburton.com>
+ * @param string $name
+ * @param mixed[] $value
+ */
protected function addImportantValue($name, $value)
{
if (in_array($name, $this->important)) {
@@ -41,15 +75,31 @@ class Handler
return $name;
}
+ /**
+ * Get a single important value
+ *
+ * @author Phil Burton <phil@pgburton.com>
+ * @param string $name
+ * @return mixed
+ */
public function returnImportant($name)
{
if (!array_key_exists($name, $this->importantValues)) {
throw new \Exception('The var ' . $name . ' is not set in this context');
}
-
+
return $this->importantValues[$name];
}
+ /**
+ * Magic __call override to be able to get improtant values using getMyImportant()
+ * which then runs $this->returnImportant('myImportant')
+ *
+ * @author Phil Burton <phil@pgburton.com>
+ * @param string $name
+ * @param mixed[] $arguments
+ * @return string
+ */
public function __call($name, $arguments)
{
if (strpos($name, 'get') === 0) {
@@ -57,16 +107,22 @@ class Handler
}
}
+ /**
+ * Render the opening message
+ *
+ * @author Phil Burton <phil@pgburton.com>
+ * @return string
+ */
public function renderOpeningMessage()
{
- $overview = new Overview();
+ $overview = new Overview();
- $overview->setFromArray($this->importantValues);
+ $overview->setFromArray($this->importantValues);
- $message = $overview->renderMessage();
+ $message = $overview->renderMessage();
- $this->setImportantValues($overview->getImportantValues());
+ $this->setImportantValues($overview->getImportantValues());
- return $message;
+ return $message;
}
-} \ No newline at end of file
+}