blob: 8729c1ae5b3b39d4f8ace126d63d5be1588f91b9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
<?php
namespace App\Message;
use App\Message\Overview;
/**
* Handles messages and context
*/
class Handler
{
protected $important = [];
protected $importantValues = [];
public function __construct($important)
{
$this->setupImportant($important);
}
/**
* Set's up important attributes on this class
*/
public function setupImportant($important = [])
{
$this->important = $important;
}
protected function setImportantValues($array)
{
foreach ($array as $name => $value) {
$this->addImportantValue($name, $value);
}
}
protected function addImportantValue($name, $value)
{
if (in_array($name, $this->important)) {
$this->importantValues[$name] = $value;
}
return $name;
}
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];
}
public function __call($name, $arguments)
{
if (strpos($name, 'get') === 0) {
$this->returnImporant(substr($name, 3));
}
}
public function renderOpeningMessage()
{
$overview = new Overview();
$message = $overview->renderMessage();
$this->setImportantValues($overview->getImportantValues());
return $message;
}
}
|