34 switch($_SERVER[
'CONTENT_TYPE'] ?? null){
35 case 'application/json':
36 if(is_array(
$data = json_decode(file_get_contents(
'php://input'),
true))) $_POST =
$data;
37 if(json_last_error()) $this->
component(
'trans')->str($this->jsonDecodingError,[
'error' => json_last_error_msg()]);
39 case 'application/xml':
40 if(is_array(
$data = json_decode(json_encode(simplexml_load_file(
'php://input',null,LIBXML_NOCDATA)),
true))) $_POST =
$data;
43 if(\
Rsi\Http::postExceeded($size,$max)){
45 $this->errors[
'post'] = $this->
component(
'trans')->str($this->postExceededError,[
'size' => $local->formatBytes($size),
'max' => $local->formatBytes($max)]);
50 $this->_fred->externalError($e->getMessage());
64 protected function fixFileKey($values,$prefix = null,$files = null){
65 if(!$prefix) $prefix = $files = [];
66 foreach($values as $key => $value){
67 $key = array_merge($prefix,[$key]);
68 if(is_array($value)) $files = $this->
fixFileKey($value,$key,$files);
70 $item = array_shift($key);
71 \Rsi\Record::set($files,array_merge($key,[$item]),$value);
84 if($keys)
foreach(array_values($keys) as $index => $key) $_GET[$key] = $argv[$index + 1] ?? null;
85 else parse_str(implode(
'&',array_slice($argv,1)),$_GET);
92 public function file($key){
93 return \Rsi\Record::get($this->files,$key);
103 public function complex($key,$default = null){
104 if(($value = \
Rsi\Record::get($_POST,$key,
false)) !==
false)
return $value;
105 if(($value = $this->
file($key)) !== null)
return $value;
106 return \Rsi\Record::iget($_GET,$key,$default);
115 public function record($key,$default = null){
116 if(!is_array($value = $this->
complex($key,$default)))
return $default;
117 foreach($value as $sub)
if(is_array($sub) || ($this->encoding && !mb_check_encoding($sub,$this->encoding)))
return $default;
128 public function simple($key,$default = null,$mask = null){
130 is_array($value = $this->
complex($key,$default)) ||
131 ($this->encoding && !mb_check_encoding($value,$this->encoding)) ||
132 ($mask && !preg_match($mask ===
true ?
'/^\\w+$/' : $mask,$value))
133 ) ? $default : $value;
136 public function data($key,$default = null){
137 return \Rsi\Record::get($this->
data,$key,$default);
148 public function cookie($key,$value = null,$days = 365,$options = null){
149 if(func_num_args() > 1) \Rsi\Http::setCookie($key,$value,$days,($options ?: []) + $this->cookieOptions);
150 return $_COOKIE[$key] ??
false;
154 if($this->_files === null){
156 foreach($_FILES as $key => $value) $this->_files[$key] = $this->
fixFileKey($value);
162 if($this->_server === null){
163 $server = [
'http' => []];
164 foreach($_SERVER as $key => $value)
165 if(substr($key = strtolower($key),0,5) ==
'http_') $server[
'http'][lcfirst(\
Rsi\Str::camel(substr($key,5)))] = $value;
166 else $server[lcfirst(\
Rsi\Str::camel($key))] = $value;
167 $this->_server = new \Rsi\Wrapper\Record($server);
173 return array_key_exists($key,$this->
data) ? $this->
data[$key] : $this->
simple($key);
176 protected function _set($key,$value){
177 $this->
data[$key] = $value;
181 return $this->
data($key,$default);
$errors
Errors detected during the processing of the request (key = item ID, value = error code)...
$redir
URL for redirection (empty = no redirection).
mapArgs($keys=null)
Map command line arguments to the $_GET.
checkPost()
Checks the post (by content type).
__invoke($key, $default=null)
record($key, $default=null)
Retrieve a record like parameter (single layer array) from the request.
data($key, $default=null)
fixFileKey($values, $prefix=null, $files=null)
Transform an array of uploaded files to a 'normal' structure.
file($key)
Retrieve a file upload from the request.
$cookieOptions
Default cookie options.
$viewControllerName
Name of the view controller (same as the request handler when empty).
$result
Result fo the request (mixed).
cookie($key, $value=null, $days=365, $options=null)
Set and/or get a cookie.
complex($key, $default=null)
Retrieve a complex parameter (simple type or array) from the request.
$data
Data to be presented by the view (key-value pairs).
Component comprising all information regarding an HTTP-request (to transport these along all stepts e...
component($name)
Get a component (local or default).
simple($key, $default=null, $mask=null)
Retrieve a simple parameter (not an array) from the request.