1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113:
<?php
namespace MvcCore\Request;
trait Instancing {
public static function CreateInstance (
array & $server = [],
array & $get = [],
array & $post = [],
array & $cookie = [],
array & $files = [],
$inputStream = NULL
) {
if (!func_get_args())
list($server, $get, $post, $cookie, $files) = [& $_SERVER, & $_GET, & $_POST, & $_COOKIE, & $_FILES];
$app = self::$app ?: (self::$app = \MvcCore\Application::GetInstance());
$requestClass = $app->GetRequestClass();
return new $requestClass($server, $get, $post, $cookie, $files, $inputStream);
}
public function __construct (
array & $server = [],
array & $get = [],
array & $post = [],
array & $cookie = [],
array & $files = [],
$inputStream = NULL
) {
$app = self::$app ?: (self::$app = \MvcCore\Application::GetInstance());
self::$routerClass = self::$routerClass ?: $app->GetRouterClass();
$this->globalServer = & $server;
$this->globalGet = & $get;
$this->globalPost = & $post;
$this->globalCookies = & $cookie;
$this->globalFiles = & $files;
$this->cli = php_sapi_name() == 'cli';
$inputStreamDefault = $this->cli
? 'php://stdin'
: 'php://input';
$this->inputStream = $inputStream !== NULL
? $inputStream
: $inputStreamDefault;
if ($this->cli)
$this->initCli();
}
public function InitAll () {
$this->GetScriptName();
$this->GetAppRoot();
$this->GetMethod();
$this->GetBasePath();
$this->GetScheme();
$this->IsSecure();
$this->GetHostName();
$this->GetHost();
$this->GetRequestPath();
$this->GetFullUrl();
$this->GetReferer();
$this->GetStartTime();
$this->IsAjax();
if ($this->port === NULL) $this->initUrlSegments();
if ($this->headers === NULL) $this->initHeaders();
if ($this->params === NULL) $this->initParams();
$this->GetServerIp();
$this->GetClientIp();
$this->GetContentLength();
return $this;
}
}