Overview

Namespaces

  • codemania
    • core
      • exception
    • library
      • database
        • drivers
  • None
  • PHP

Classes

  • Cookie
  • Core
  • Crypt
  • HTTP
  • Request
  • Route
  • Security
  • Singleton
  • Overview
  • Namespace
  • Class
  • Tree
  • Deprecated
  • Todo
  • Download
 1: <?php
 2: namespace codemania\core;
 3: /**
 4:  * CodeMania Framework
 5:  * 
 6:  * @author CodeMania Team <team@codemania.ru>
 7:  * @package CodeMania
 8:  * @version 1.0.0
 9:  * @copyright (c) 2014, CodeMania Team
10:  * @link  http://codemania.ru
11:  * @license http://codemania.ru/license.html
12:  */
13: defined('CM_ROOT') or exit('Запрет доступа!');
14: /**
15:  * 
16:  * @author CodeMania Team <team@codemania.ru>
17:  * @license http://codemania.ru/license.html
18:  * @package CodeMania
19:  * @version 1.0.0
20:  * @copyright (c) 2014, CodeMania Team
21:  * @link  http://guide.codemania.ru/class_Request.html
22:  */
23: class Request extends Route {
24:     /**
25:      * Директория контроллеров приложений
26:      * @const APPPATH
27:      */
28:     const APPPATH = 'application\classes\controllers\\';
29:     /**
30:      * Дериктория модулей 
31:      * @MODPATH
32:      */
33:     const MODPATH = 'application\modules\\';
34:     /**
35:      * Конструктор класса
36:      */
37:     public function __construct() {
38:         // Иницилизируем конструктор родительского класса 
39:         // и передаем ему URI
40:         parent::__construct($this->_detect_uri());
41:     }
42:     /**
43:      * Вычисляет строку URI запроса
44:      * @return string Обработанная строка запроса
45:      */
46:     private function _detect_uri() {
47:         // Проверяем наличие запроса после имени скрипта
48:             if (isset($_SERVER['PATH_INFO']) && !empty($_SERVER['PATH_INFO'])) {
49:                 $uri = $_SERVER['PATH_INFO'];
50:                 // Или берем из URI
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: }
CodeMania Framework API documentation generated by ApiGen 2.8.0