32 if (! isset ( $values )) {
35 foreach ( $values as $key => $value ) {
36 $accessor =
'set' . \ucfirst ( $key );
37 if (\method_exists ( $object, $accessor )) {
38 $object->$accessor ( $value );
39 $object->_rest [$key] = $value;
51 self::setValuesToObject ( $object, $_GET );
61 self::setValuesToObject ( $object, $_POST );
70 public static function getPost($function =
'htmlentities'): array {
71 return \array_map ( $function, $_POST );
78 return
Startup::getHttpInstance ()->getInput ();
87 $method = \strtolower ( $_SERVER [
'REQUEST_METHOD'] );
90 if (self::getContentType () ==
'application/x-www-form-urlencoded') {
97 return self::getInput ();
99 return self::getInput ();
110 public static function set(
string $key, $value =
true) {
111 return $_REQUEST [$key] = $value;
121 if (isset ( $_SERVER [
'HTTP_ACCEPT_LANGUAGE'] )) {
122 return self::parseDefaultLanguage ( $_SERVER [
'HTTP_ACCEPT_LANGUAGE'] );
124 return self::parseDefaultLanguage ( NULL );
128 if (isset ( $http_accept ) && \strlen ( $http_accept ) > 1) {
129 $x = \explode (
",", $http_accept );
131 foreach ( $x as $val ) {
132 if (\preg_match (
"/(.*);q=([0-1]{0,1}.\d{0,4})/i", $val, $matches )) {
133 $lang [$matches [1]] = ( float )$matches [2];
140 foreach ( $lang as $key => $value ) {
141 if ($value > $qval) {
142 $qval = ( float ) $value;
150 public static function setLocale(
string $locale): void {
152 if (\class_exists (
'Locale', false )) {
153 \Locale::setDefault ( $locale );
155 }
catch ( \Exception $e ) {
168 public static function get(
string $key, $default = NULL): ?string {
169 return $_GET [$key] ?? $default;
180 if (isset ( $_REQUEST [$key] )) {
181 $ret = UString::isBooleanTrue ( $_REQUEST [$key] );
193 public static function post(
string $key, $default = NULL) {
194 return $_POST [$key] ?? $default;
197 public static function getUrl($url): string {
198 $config =
Startup::getConfig ();
199 $siteUrl = \rtrim ( $config [
'siteUrl'],
'/' );
200 if (UString::startswith ( $url,
'/' ) ===
false) {
203 return $siteUrl . $url;
207 return \explode (
'/', $_GET [
'c'] );
216 return \strtolower ( $_SERVER [
'REQUEST_METHOD'] );
225 $headers =
Startup::getHttpInstance ()->getAllHeaders ();
226 return $headers [
'Origin']??$_SERVER [
'HTTP_ORIGIN']??$_SERVER [
'HTTP_REFERER']??$_SERVER [
'REMOTE_ADDR']??
'';
230 $url = \str_replace (
"\\",
"/", $url );
231 return \str_replace (
"//",
"/", $url );
243 $pairs = \explode (
'&', \strtolower ( $source ) ===
'get' ? $_SERVER [
'QUERY_STRING'] : \file_get_contents (
'php://input' ) );
245 foreach ( $pairs as $pair ) {
246 $nv = \explode (
"=", $pair );
247 $name = \urldecode ( $nv [0] );
248 $value = \urldecode ( $nv [1] ??
'');
249 $vars [$name] = $value;
255 return self::getRealInput (
'get' );
259 return self::getRealInput (
'post' );
269 public static function password_hash(
string $key,
string $algo = PASSWORD_DEFAULT) {
270 if (isset ( $_POST [$key] )) {
271 return $_POST [$key] = \password_hash ( $_POST [$key], $algo );
286 if (isset ( $_POST [$passwordKey] )) {
287 return \password_verify( $_POST [$passwordKey], $hash );
298 public static function parseURI(
string $uri,
string $basedir):array {
299 return self::$uriInfos[$uri]??=self::_parseURI($uri,$basedir);
310 public static function filter(
string $key,
int $type=\INPUT_POST,
int $filter=\FILTER_DEFAULT,$default=
null){
311 return \filter_input($type,$key,$filter)??$default;
321 public static function filterPost(
string $key,
int $filter=\FILTER_DEFAULT,$default=
null){
322 return self::filter($key,INPUT_POST,$filter,$default);
332 public static function filterGet(
string $key,
int $filter=\FILTER_DEFAULT,$default=
null){
333 return self::filter($key,INPUT_GET,$filter,$default);
336 private static function _parseURI(
string $uri,
string $basedir):array {
337 $uri = \ltrim(\urldecode(\parse_url($uri, PHP_URL_PATH)),
'/');
338 $isAction = ($uri ==
null || ! ($fe = \file_exists($basedir .
'/' . $uri))) && ($uri !=
'favicon.ico');
341 'isAction' => $isAction,
Http Request utilities, wrapper for accessing to $_GET, $_POST and php://input.
static _parseURI(string $uri, string $basedir)
static getMethod()
Returns the http method.
static getPost($function='htmlentities')
Call a cleaning function on the post.
static getRealInput($source='post')
Fix up PHP's messing up input containing dots, etc.
static setValuesToObject($object, $values=null)
Affects member to member the values of the associative array $values to the members of the object $ob...
static parseDefaultLanguage($http_accept, $deflang='en')
static post(string $key, $default=NULL)
Returns the value of the $key variable passed by the post method or $default if the $key variable doe...
static getDefaultLanguage()
Copyright © 2008 Darrin Yeager https://www.dyeager.org/ Licensed under BSD license.
static setPostValuesToObject($object)
Affects member to member the values of $_POST to the members of the object $object $object must have ...
static filter(string $key, int $type=\INPUT_POST, int $filter=\FILTER_DEFAULT, $default=null)
Gets a specific external variable by name and optionally filters it.
static filterGet(string $key, int $filter=\FILTER_DEFAULT, $default=null)
Gets a specific GET variable by name and optionally filters it.
static password_hash(string $key, string $algo=PASSWORD_DEFAULT)
Creates a password hash for a posted value at $key position.
static getDatas()
Returns the query data, regardless of the method.
static parseURI(string $uri, string $basedir)
Internal use for async servers (Swoole and Workerman).
static password_verify(string $passwordKey, string $hash)
Verifies that a posted password matches a hash at $passwordKey position.
static getInput()
Returns the query data, for PUT, DELETE PATCH methods.
static setGetValuesToObject($object)
Affects member to member the values of $_GET to the members of the object $object $object must have a...
static getBoolean(string $key)
Returns a boolean at the key position in request.
static setLocale(string $locale)
static filterPost(string $key, int $filter=\FILTER_DEFAULT, $default=null)
Gets a specific POST variable by name and optionally filters it.
static getOrigin()
Returns the request origin.
Ubiquity\utils\http\traits$URequestTesterTrait This class is part of Ubiquity.