1: <?php
2: namespace codemania\core;
3: 4: 5: 6: 7: 8: 9: 10: 11: 12:
13: defined('CM_ROOT') or exit('Запрет доступа!');
14: 15: 16: 17: 18: 19: 20: 21: 22:
23: class Request extends Route {
24: 25: 26: 27:
28: const APPPATH = 'application\classes\controllers\\';
29: 30: 31: 32:
33: const MODPATH = 'application\modules\\';
34: 35: 36:
37: public function __construct() {
38:
39:
40: parent::__construct($this->_detect_uri());
41: }
42: 43: 44: 45:
46: private function _detect_uri() {
47:
48: if (isset($_SERVER['PATH_INFO']) && !empty($_SERVER['PATH_INFO'])) {
49: $uri = $_SERVER['PATH_INFO'];
50:
51: } elseif (isset($_SERVER['REQUEST_URI'])) {
52:
53: $ex = explode('?', $_SERVER['REQUEST_URI']);
54: $uri = $ex[0];
55:
56: if (stripos($uri, $_SERVER['SCRIPT_NAME']) === 0) {
57: $uri = substr($uri, strlen($_SERVER['SCRIPT_NAME']));
58: }
59: }
60:
61: return rawurldecode(trim($uri, '/'));
62: }
63: 64: 65:
66: public function body() {
67: if ( ! $this->_get_controller_app()) {
68: if ( ! $this->_get_default_controller()) {
69:
70: }
71: }
72: }
73: private function _get_controller_app($controller, $method) {
74: $path = self::APPPATH . ucfirst($controller) .'_Controller';
75: if (file_exists(CM_ROOT . $path.'.php') && @class_exists($path)) {
76: if (method_exists($path, $method)) {
77: return (new $path)->$method();
78: }
79: }
80: return false;
81: }
82: private function _get_default_controller() {
83: $path = self::APPPATH . self::$_default .'_Controller';
84: $path2 = self::MODPATH . self::$_default .'/'. self::$_default .'_Controller';
85: if (file_exists(CM_ROOT . $path.'.php') && @class_exists($path)) {
86: if (method_exists($path, 'index')) {
87: return (new $path)->index();
88: }
89: } elseif (file_exists(CM_ROOT . $path2.'.php') && @class_exists($path2)) {
90: if (method_exists($path2, 'index')) {
91: return (new $path2)->index();
92: }
93: }
94: return false;
95: }
96: }