mirror of
https://github.com/glmdev/eecs448-lab10
synced 2026-03-02 03:39:24 +00:00
Initial commit
This commit is contained in:
40
common/Request.php
Normal file
40
common/Request.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace common;
|
||||
|
||||
class Request {
|
||||
protected $_get = [];
|
||||
protected $_post = [];
|
||||
|
||||
public static function capture() {
|
||||
$req = new static();
|
||||
$req->_get = $_GET;
|
||||
$req->_post = $_POST;
|
||||
return $req;
|
||||
}
|
||||
|
||||
public function input($path = null) {
|
||||
if ( !$path ) {
|
||||
return array_merge($this->_get, $this->_post);
|
||||
}
|
||||
|
||||
$path_parts = explode('.', $path);
|
||||
|
||||
$get_value = $this->_get;
|
||||
foreach ( $path_parts as $part ) {
|
||||
if ( $get_value ) {
|
||||
$get_value = $get_value[$part];
|
||||
}
|
||||
}
|
||||
|
||||
$post_value = $this->_post;
|
||||
foreach ( $path_parts as $part ) {
|
||||
if ( $post_value ) {
|
||||
$post_value = $post_value[$part];
|
||||
}
|
||||
}
|
||||
|
||||
if ( $get_value ) return $get_value;
|
||||
if ( $post_value ) return $post_value;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user