123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- <?php
- namespace app;
- use app\utils\Str;
- class Request
- {
-
- * 请求方法是否为Post
- * @var bool
- */
- protected $isPost = false;
-
- * 控制器名
- * @var string
- */
- public $controller;
-
- * 操作名
- * @var string
- */
- public $actionName;
-
- * 参数
- * @var array
- */
- public $params;
-
- * 初始化
- * @var bool
- */
- protected static $initialized = false;
-
- private static $instance;
-
- private function __construct(){
-
- }
- public static function getInstance($initforce = false){
-
- if (!self::$instance instanceof self) {
- self::$instance = new self();
- }
-
- if ($initforce || !self::$initialized) {
- self::$instance->init();
- }
- return self::$instance;
- }
- public function init()
- {
- self::$initialized = true;
- if ($_SERVER['REQUEST_METHOD'] == 'POST') {
- $this->isPost = true;
- }
- $pathinfo = "";
- if (isset($_SERVER['PATH_INFO']) && !empty($_SERVER['PATH_INFO']) ) {
- $pathinfo = $_SERVER['PATH_INFO'];
- } else {
- $pathinfo = strpos($_SERVER['REQUEST_URI'], '?') ? strstr($_SERVER['REQUEST_URI'], '?', true) : $_SERVER['REQUEST_URI'];
- }
- if (is_string($pathinfo)) {
- $result = explode('/', trim($pathinfo,'/'));
- }
-
-
-
-
-
-
-
-
- $this->controller = "Index";
- $this->actionName = strip_tags(isset($result[0]) && !empty($result[0]) ? $result[0] : 'index');
-
- $doc = '';
- if (count($result) > 1)
- {
- for ($i = 1; $i < count($result); $i++) {
- $doc .= '/' . $result[$i];
- }
- }
- $this->params = array_merge($_GET, $_POST, ['doc'=>$doc]);
- return $this;
- }
-
- * 是否初始化过
- * @return bool
- */
- public function initialized()
- {
- return $this->initialized;
- }
- public function isPost()
- {
- return $this->isPost;
- }
- }
|