Ubiquity 2.5.2
php rapid development framework
Loading...
Searching...
No Matches
UResponse Class Reference

Http Response utilities. More...

Static Public Member Functions

static header ($headerField, $value, bool $replace=true, int $responseCode=0)
 Send a raw HTTP header.
 
static forward (string $url, bool $preserveUrl=true)
 Forwards to url using Location header.
 
static setContentType ($contentType, $encoding=null)
 Sets header content-type.
 
static noCache ()
 Forces the disabling of the browser cache.
 
static isSent (&$file=null, &$line=null)
 Checks if or where headers have been sent.
 
static asJSON ()
 Sets the response content-type to application/json.
 
static isJSON ()
 Tests if response content-type is application/json Only Works if UResponse has been used for setting headers.
 
static asHtml ($encoding='utf-8')
 Sets the response content-type to text/html.
 
static asXml ($encoding='utf-8')
 Sets the response content-type to application/xml.
 
static asText ($encoding='utf-8')
 Sets the response content-type to plain/text.
 
static setAccept ($value)
 Sets the Accept header.
 
static enableCors ($origin=' *', $methods='GET, POST, PUT, DELETE, PATCH, OPTIONS', $headers='X-Requested-With, Content-Type, Accept, Origin, Authorization')
 Enables CORS.
 
static setAccessControlOrigin ($origin=' *')
 Sets the Access-Control-Allow-Origin field value Only a single origin can be specified.
 
static setAccessControlMethods ($methods)
 Sets the Access-Control-Allow-Methods field value.
 
static setAccessControlHeaders ($headers)
 Sets the Access-Control-Allow-Headers field value.
 
static setAuthorization ($authorization)
 Set the Authorization header field.
 
static setResponseCode ($value)
 Sets the response code.
 
static getResponseCode ()
 Get the response code.
 

Static Public Attributes

static $headers = [ ]
 

Static Private Member Functions

static _headerArray ($headerField, $values)
 

Detailed Description

Http Response utilities.

Ubiquity\utils\http$UResponse This class is part of Ubiquity

Author
jcheron myadd.nosp@m.ress.nosp@m.mail@.nosp@m.gmai.nosp@m.l.com
Version
1.1.3

Definition at line 17 of file UResponse.php.

Member Function Documentation

◆ _headerArray()

static _headerArray (   $headerField,
  $values 
)
staticprivate
Parameters
string$headerField
mixed$values

Definition at line 47 of file UResponse.php.

◆ asHtml()

static asHtml (   $encoding = 'utf-8')
static

Sets the response content-type to text/html.

Parameters
string$encodingdefault: utf-8

Definition at line 108 of file UResponse.php.

◆ asJSON()

static asJSON ( )
static

Sets the response content-type to application/json.

Definition at line 89 of file UResponse.php.

◆ asText()

static asText (   $encoding = 'utf-8')
static

Sets the response content-type to plain/text.

Parameters
string$encodingdefault: utf-8

Definition at line 126 of file UResponse.php.

◆ asXml()

static asXml (   $encoding = 'utf-8')
static

Sets the response content-type to application/xml.

Parameters
string$encodingdefault: utf-8

Definition at line 117 of file UResponse.php.

◆ enableCors()

static enableCors (   $origin = '*',
  $methods = 'GET,
POST  ,
PUT  ,
DELETE  ,
PATCH  ,
OPTIONS'  ,
  $headers = 'X-Requested-With,
Content-  Type,
Accept  ,
Origin  ,
Authorization'   
)
static

Enables CORS.

Parameters
string$originThe allowed origin (default: '*')
string$methodsThe allowed methods (default: 'GET, POST, PUT, DELETE, PATCH, OPTIONS')
string$headersThe allowed headers (default: 'X-Requested-With, Content-Type, Accept, Origin, Authorization')
Since
Ubiquity 2.0.11

Definition at line 148 of file UResponse.php.

◆ forward()

static forward ( string  $url,
bool  $preserveUrl = true 
)
static

Forwards to url using Location header.

Parameters
string$url
bool$preserveUrl

Definition at line 38 of file UResponse.php.

◆ getResponseCode()

static getResponseCode ( )
static

Get the response code.

Returns
int|bool

Definition at line 208 of file UResponse.php.

◆ header()

static header (   $headerField,
  $value,
bool  $replace = true,
int  $responseCode = 0 
)
static

Send a raw HTTP header.

Parameters
string$headerFieldthe header field
string$valuethe header value
boolean$replaceThe optional replace parameter indicates whether the header should replace a previous similar header
int$responseCodeForces the HTTP response code to the specified value

Definition at line 28 of file UResponse.php.

◆ isJSON()

static isJSON ( )
static

Tests if response content-type is application/json Only Works if UResponse has been used for setting headers.

Returns
boolean

Definition at line 99 of file UResponse.php.

◆ isSent()

static isSent ( $file = null,
$line = null 
)
static

Checks if or where headers have been sent.

Parameters
string$fileIf the optional file and line parameters are set,headers_sent will put the PHP source file nameand line number where output started in the fileand line variables.
int$lineThe line number where the output started.
Returns
boolean

Definition at line 82 of file UResponse.php.

◆ noCache()

static noCache ( )
static

Forces the disabling of the browser cache.

Definition at line 70 of file UResponse.php.

◆ setAccept()

static setAccept (   $value)
static

Sets the Accept header.

Parameters
string$valueone of Http accept values
See also
https://developer.mozilla.org/en-US/docs/Web/HTTP/Content_negotiation/List_of_default_Accept_values

Definition at line 136 of file UResponse.php.

◆ setAccessControlHeaders()

static setAccessControlHeaders (   $headers)
static

Sets the Access-Control-Allow-Headers field value.

Parameters
string | array$headers

Definition at line 181 of file UResponse.php.

◆ setAccessControlMethods()

static setAccessControlMethods (   $methods)
static

Sets the Access-Control-Allow-Methods field value.

Parameters
string | array$methods

Definition at line 172 of file UResponse.php.

◆ setAccessControlOrigin()

static setAccessControlOrigin (   $origin = '*')
static

Sets the Access-Control-Allow-Origin field value Only a single origin can be specified.

Parameters
string$origin

Definition at line 160 of file UResponse.php.

◆ setAuthorization()

static setAuthorization (   $authorization)
static

Set the Authorization header field.

Parameters
string$authorization

Definition at line 190 of file UResponse.php.

◆ setContentType()

static setContentType (   $contentType,
  $encoding = null 
)
static

Sets header content-type.

Parameters
string$contentType
string$encoding

Definition at line 60 of file UResponse.php.

◆ setResponseCode()

static setResponseCode (   $value)
static

Sets the response code.

Parameters
int$value

Definition at line 199 of file UResponse.php.

Field Documentation

◆ $headers

$headers = [ ]
static

Definition at line 18 of file UResponse.php.


The documentation for this class was generated from the following file: