| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- <?php
- namespace ThurData\Servers\KerioEmail\Core\App\Controllers;
- class Router
- {
- use \ThurData\Servers\KerioEmail\Core\Traits\Lang;
- use \ThurData\Servers\KerioEmail\Core\Traits\Smarty;
- use \ThurData\Servers\KerioEmail\Core\Traits\OutputBuffer;
- use \ThurData\Servers\KerioEmail\Core\Traits\IsAdmin;
- use \ThurData\Servers\KerioEmail\Core\UI\Traits\RequestObjectHandler;
- const ADMIN = 'admin';
- const CLIENT = 'client';
- protected $controllerClass = null;
- protected $controllerMethod = null;
- public function __construct()
- {
- $this->isAdmin();
- $this->loadController();
- }
- /**
- * load routing params
- */
- public function loadController()
- {
- $this->getControllerClass();
- $this->getControllerMethod();
- }
- /**
- * @return string
- * class name of the controller
- */
- public function getControllerClass()
- {
- if ($this->controllerClass === null)
- {
- $this->controllerClass = '\ThurData\Servers\KerioEmail\App\Http\\' . ucfirst($this->getControllerType()) . '\\' . ucfirst($this->getController());
- }
- return $this->controllerClass;
- }
- /**
- * @return string
- * admin/client context type
- */
- public function getControllerType()
- {
- return $this->isAdminStatus ? self::ADMIN : self::CLIENT;
- }
- /**
- * @return string
- * get controller name
- */
- public function getController()
- {
- return filter_var($this->getRequestValue('mg-page', 'Home'), FILTER_SANITIZE_SPECIAL_CHARS);
- }
- /**
- * @return string
- * controller method name
- */
- public function getControllerMethod()
- {
- if ($this->controllerMethod === null)
- {
- $this->controllerMethod = $this->request->get('mg-action', 'index');
- }
- return $this->controllerMethod;
- }
- /**
- * @return bool
- * determines if controller can be called
- */
- public function isControllerCallable()
- {
- if (!class_exists($this->controllerClass))
- {
- return false;
- }
- if (!method_exists($this->controllerClass, $this->controllerMethod))
- {
- return false;
- }
- if (!is_callable([$this->controllerClass, $this->controllerMethod]))
- {
- return false;
- }
- return true;
- }
- }
|