1: <?php
2:
3: namespace Deimos\Controller;
4:
5: use Deimos\Controller\Exceptions\DisplayNone;
6: use Deimos\Controller\Exceptions\RequestNotFound;
7:
8: abstract class Controller extends Proxy
9: {
10:
11: 12: 13: 14: 15: 16: 17:
18: public function execute()
19: {
20: $this->configure();
21: $this->before();
22:
23: $name = $this->request()->attribute('action');
24: $data = $this->instance($name);
25:
26: $this->after($data);
27:
28: return $this->display($data);
29: }
30:
31: 32: 33: 34: 35: 36:
37: protected function display($data)
38: {
39: if (is_string($data))
40: {
41: return $data;
42: }
43:
44: if (is_array($data) || $data instanceof \stdClass)
45: {
46: return $this->helper()->json()->encode($data);
47: }
48:
49: throw new DisplayNone('Undefined value \'' . $data . '\'');
50: }
51:
52: }