*/ 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 * @param string[] $important */ public function __construct($important) { $this->setupImportant($important); } /** * Set the important list * * @author Phil Burton * @param string[] $important */ public function setupImportant($important = []) { $this->important = $important; } /** * Set important values * * @author Phil Burton * @param mixed[] $array */ protected function setImportantValues($array) { foreach ($array as $name => $value) { $this->addImportantValue($name, $value); } } /** * Add an important value to our array * * @author Phil Burton * @param string $name * @param mixed[] $value */ protected function addImportantValue($name, $value) { if (in_array($name, $this->important)) { $this->importantValues[$name] = $value; } return $name; } /** * Get a single important value * * @author Phil Burton * @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 * @param string $name * @param mixed[] $arguments * @return string */ public function __call($name, $arguments) { if (strpos($name, 'get') === 0) { $this->returnImporant(substr($name, 3)); } } /** * Render the opening message * * @author Phil Burton * @return string */ public function renderOpeningMessage() { $overview = new Overview(); $overview->setFromArray($this->importantValues); $message = $overview->renderMessage(); $this->setImportantValues($overview->getImportantValues()); return $message; } }