mirror of
https://github.com/skipperbent/simple-php-router.git
synced 2026-07-11 21:02:15 +00:00
[FEATURE] Added magic method getters and setters, and made request a
singleton applied configuration can be availible from everywhere.
This commit is contained in:
@@ -3,12 +3,27 @@ namespace Pecee\Http;
|
|||||||
|
|
||||||
class Request {
|
class Request {
|
||||||
|
|
||||||
|
protected static $instance;
|
||||||
|
|
||||||
|
protected $data;
|
||||||
protected $uri;
|
protected $uri;
|
||||||
protected $host;
|
protected $host;
|
||||||
protected $method;
|
protected $method;
|
||||||
protected $headers;
|
protected $headers;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return new instance
|
||||||
|
* @return static
|
||||||
|
*/
|
||||||
|
public static function getInstance() {
|
||||||
|
if(self::$instance === null) {
|
||||||
|
self::$instance = new static();
|
||||||
|
}
|
||||||
|
return self::$instance;
|
||||||
|
}
|
||||||
|
|
||||||
public function __construct() {
|
public function __construct() {
|
||||||
|
$this->data = array();
|
||||||
$this->host = $_SERVER['HTTP_HOST'];
|
$this->host = $_SERVER['HTTP_HOST'];
|
||||||
$this->uri = $_SERVER['REQUEST_URI'];
|
$this->uri = $_SERVER['REQUEST_URI'];
|
||||||
$this->method = (isset($_POST['_method'])) ? strtolower($_POST['_method']) : strtolower($_SERVER['REQUEST_METHOD']);
|
$this->method = (isset($_POST['_method'])) ? strtolower($_POST['_method']) : strtolower($_SERVER['REQUEST_METHOD']);
|
||||||
@@ -103,4 +118,12 @@ class Request {
|
|||||||
return (isset($_REQUEST[$name]) ? $_REQUEST[$name] : $defaultValue);
|
return (isset($_REQUEST[$name]) ? $_REQUEST[$name] : $defaultValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function __set($name, $value = null) {
|
||||||
|
$this->data[$name] = $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function __get($name) {
|
||||||
|
return isset($this->data[$name]) ? $this->data[$name] : null;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user