1 | <?php |
||
24 | abstract class Controller |
||
25 | { |
||
26 | |||
27 | /** |
||
28 | * Holds the views per controller request |
||
29 | * @var array |
||
30 | */ |
||
31 | private $viewArray = []; |
||
32 | |||
33 | /** |
||
34 | * Controller constructor. |
||
35 | * @param Request $request |
||
36 | */ |
||
37 | public function __construct(Request $request) |
||
41 | |||
42 | /** |
||
43 | * Returns the service locator |
||
44 | * |
||
45 | * @return ServiceLocator |
||
46 | */ |
||
47 | public function getServiceLocator() :ServiceLocator |
||
51 | |||
52 | /** |
||
53 | * Returns the session manager |
||
54 | * |
||
55 | * @return SessionManager |
||
56 | */ |
||
57 | public function getSessionManager() :SessionManager |
||
61 | |||
62 | /** |
||
63 | * Returns the view controller |
||
64 | * |
||
65 | * @return ViewController |
||
66 | */ |
||
67 | public function getView() :ViewController |
||
80 | |||
81 | /** |
||
82 | * Returns the orm/entity manager |
||
83 | * |
||
84 | * @return DbService|ServiceInterface |
||
85 | */ |
||
86 | public function getDb() :DbService |
||
90 | |||
91 | /** |
||
92 | * Render view with given template |
||
93 | * |
||
94 | * @param string $template |
||
95 | * @param array $variables |
||
96 | * @return string |
||
97 | */ |
||
98 | public function render(string $template = '', $variables = []) :string |
||
102 | |||
103 | /** |
||
104 | * Set required authentication |
||
105 | * |
||
106 | * @param array $role |
||
107 | * @return bool |
||
108 | */ |
||
109 | public function requireAuth($role) :bool |
||
120 | |||
121 | /** |
||
122 | * @param string $uri |
||
123 | * @return bool |
||
124 | */ |
||
125 | public function redirect(string $uri) :bool |
||
131 | |||
132 | /** |
||
133 | * @return Request |
||
134 | */ |
||
135 | public function getRequest() :Request |
||
139 | |||
140 | } |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: