Ubiquity 2.5.2
php rapid development framework
Loading...
Searching...
No Matches
URequestTesterTrait.php
Go to the documentation of this file.
1<?php
2
4
6
16
24 public static function filled($key): bool {
25 return isset ( $_REQUEST [$key] ) && $_REQUEST [$key] != null;
26 }
27
35 public static function has($key): bool {
36 return isset ( $_REQUEST [$key] );
37 }
38
44 public static function isAjax(): bool {
45 return (isset ( $_SERVER ['HTTP_X_REQUESTED_WITH'] ) && ! empty ( $_SERVER ['HTTP_X_REQUESTED_WITH'] ) && strtolower ( $_SERVER ['HTTP_X_REQUESTED_WITH'] ) == 'xmlhttprequest');
46 }
47
53 public static function isPost(): bool {
54 return $_SERVER ['REQUEST_METHOD'] === 'POST';
55 }
56
66 public static function isCrossSite(): bool {
67 return \stripos ( $_SERVER ['HTTP_REFERER'], $_SERVER ['SERVER_NAME'] ) === FALSE;
68 }
69
75 public static function isJSON(): bool {
76 $contentType = self::getContentType ();
77 return \stripos ( $contentType, 'json' ) !== false;
78 }
79
85 public static function getContentType(): ?string {
86 $headers = Startup::getHttpInstance ()->getAllHeaders ();
87 if (isset ( $headers ['Content-Type'] )) {
88 return $headers ['Content-Type'];
89 }
90 return null;
91 }
92}
93
Starts the framework.
Definition Startup.php:19
Ubiquity\utils\http\traits$URequestTesterTrait This class is part of Ubiquity.
static isJSON()
Returns true if request contentType is set to json.
static getContentType()
Returns the request content-type header.
static isPost()
Returns true if the request is sent by the POST method.
static isAjax()
Returns true if the request is an Ajax request.
static isCrossSite()
Returns true if the request is cross site.
static has($key)
Tests if a value is present on the request.
static filled($key)
Tests if a value is present on the request and is not empty.