Response Class. More...
Public Member Functions | |
__construct () | |
Constructor. | |
reset () | |
Reset the axResponse instance to its initial state. | |
getView () | |
Get the view name. | |
setView ($view) | |
Set view name. | |
getViewSection () | |
Get the view section. | |
setViewSection ($section) | |
set View section | |
getFormat () | |
Get view format. | |
setFormat ($format) | |
Set view format. | |
getLayout () | |
Get view layout. | |
setLayout ($layout) | |
Set view layout. | |
enableLayout ($enabled=true) | |
Enable of disable layout according to the $enabled parameter. | |
layoutState () | |
Tells if the layout is enabled or not. | |
getVar ($name) | |
Get the given var. | |
setVar ($name, $value) | |
Set the given var. | |
__get ($key) | |
__get implementation | |
__set ($key, $value) | |
__set implementation | |
getVars () | |
Get all the registered var. | |
add ($collection, $method=self::MERGE_VARS) | |
Add or merge a collection to the current registered variables. | |
clearVars () | |
Remove all the registered variables. | |
setHeader ($field, $value) | |
Add an header to the header list. | |
setHaders (array $headers) | |
Set multiple headers at once. | |
setStatus ($http_status) | |
Set the HTTP status http://en.wikipedia.org/wiki/List_of_HTTP_status_codes. | |
getHeaders () | |
Get the headers list. | |
clearHeaders () | |
Clear all registered headers. | |
setOutputCallback ($callback) | |
Set a callback to be executed on the output buffer before it is sent to the browser. | |
getOutputCallback () | |
Get the output callback. | |
hasFilter () | |
Tells whenever a filter has been registered or not. | |
getFilter () | |
Get the registered filter. | |
setFilter (array $filter) | |
Set a response variable filter. | |
addMessage ($message, $level=self::MESSAGE_WARNING) | |
Adds a view message. | |
removeMessage ($message) | |
getMessages ($level=null) | |
Get all view messages, optionnaly filtered by their level. | |
clearMessages () | |
Erase all registered messages. | |
addStyleSheet ($stylesheet, $type="text/css", $media="screen") | |
Add a view style sheet. | |
removeStyleSheet ($stylehseet) | |
Remove a style sheet (identified by its `href` attribute) | |
clearStyleSheets () | |
Erase all registered stylesheets. | |
addScript ($script, $type="text/javascript") | |
removeScript ($script) | |
Remove a script (identified by its `src`) | |
clearScripts () | |
Erase all registered scripts. | |
setCookie ($name, $value="", $expire=0, $path="", $domain="", $secure=false, $httponly=false) | |
PHP setcookie alias. | |
setRawCookie ($name, $value="", $expire=0, $path="", $domain="", $secure=false, $httponly=false) | |
PHP setrawcookie alias. | |
Data Fields | |
const | MERGE_VARS = "merge" |
const | ADD_VARS = "add" |
const | MESSAGE_NOTICE = "notice" |
const | MESSAGE_WARNING = "warning" |
const | MESSAGE_ALERT = "alert" |
const | HEADER_ACCEPT_RANGE = "Accept-Ranges" |
const | HEADER_AGE = "Age" |
const | HEADER_ALLOW = "Allow" |
const | HEADER_CACHE_CONTROL = "Cache-Control" |
const | HEADER_CONNECTION = "Connection" |
const | HEADER_CONTENT_ENCODING = "Content-Encoding" |
const | HEADER_CONTENT_LANGUAGE = "Content-Language" |
const | HEADER_CONTENT_LENGTH = "Content-Length" |
const | HEADER_CONTENT_LOCATION = "Content-Location" |
const | HEADER_CONTENT_MD5 = "Content-MD5" |
const | HEADER_CONTENT_DISPOSITION = "Content-Disposition" |
const | HEADER_CONTENT_RANGE = "Content-Range" |
const | HEADER_CONTENT_TYPE = "Content-Type" |
const | HEADER_DATE = "Date" |
const | HEADER_ETAG = "ETag" |
const | HEADER_EXPIRES = "Expires" |
const | HEADER_LAST_MODIFIED = "Last-Modified" |
const | HEADER_LINK = "Link" |
const | HEADER_LOCATION = "Location" |
const | HEADER_P3P = "P3P" |
const | HEADER_PRAGMA = "Pragma" |
const | HEADER_PROXY_AUTHENTICATE = "Proxy-Authenticate" |
const | HEADER_REFRESH = "Refresh" |
const | HEADER_RETRY_AFTER = "Retry-After" |
const | HEADER_SERVER = "Server" |
const | HEADER_SET_COOKIE = "Set-Cookie" |
const | HEADER_STS = "Strict-Transport-Security" |
const | HEADER_TRAILER = "Trailer" |
const | HEADER_TRANSFER_ENCODING = "Transfer-Encoding" |
const | HEADER_VARY = "Vary" |
const | HEADER_VIA = "Via" |
const | HEADER_WARNING = "Warning" |
const | HEADER_WWW_AUTHENTICATE = "WWW-Authenticate" |
Protected Member Functions | |
_applyFilter () | |
If any, apply the filter on the registered variables. | |
Protected Attributes | |
$_view | |
View name. | |
$_viewSection | |
View section. | |
$_viewFormat | |
View format. | |
$_viewLayout | |
Layout name. | |
$_layoutEnabled | |
Enabled layout flag. | |
$_vars | |
View variables. | |
$_headers | |
Response Headers. | |
$_outputCallback | |
$_filter | |
$_filterFlag | |
Filter flag. | |
$_messages | |
View messages. | |
$_styleSheets | |
$_scripts | |
View scripts. |
Response Class.
Definition at line 17 of file axResponse.class.php.
Constructor.
Definition at line 107 of file axResponse.class.php.
axResponse::__get | ( | $ | key | ) |
__get implementation
string | $key |
Definition at line 273 of file axResponse.class.php.
axResponse::__set | ( | $ | key, |
$ | value | ||
) |
__set implementation
string | $key | |
mixed | $value |
Definition at line 285 of file axResponse.class.php.
axResponse::_applyFilter | ( | ) | [protected] |
If any, apply the filter on the registered variables.
If the filter fails, all variables will be erased as well as the registered filter to prevent the script to be stuck. A RuntimeException will also be thrown.
RuntimeException | If the filter fails |
Definition at line 674 of file axResponse.class.php.
axResponse::add | ( | $ | collection, |
$ | method = self::MERGE_VARS |
||
) |
Add or merge a collection to the current registered variables.
Will return false if the $method
parameter is unknown.
array | $collection | |
string | $method | [optional] [default axResponse::MERGE_VARS ] Possible values are axResponse::MERGE_VARS or axResponse::ADD_VARS |
Definition at line 316 of file axResponse.class.php.
axResponse::addMessage | ( | $ | message, |
$ | level = self::MESSAGE_WARNING |
||
) |
Adds a view message.
For convenience, the `$message` parameter will be casted to string. Custom levels are authorized.
string | $message | |
strign | $level | [optional] [default axResponse::MESSAGE_WARNING ] One of axResponse::MESSAGE_WARNING,axResponse::MESSAGE_NOTICE, or axResponse::MESSAGE_ALERT or any string describing a level |
Definition at line 499 of file axResponse.class.php.
axResponse::addScript | ( | $ | script, |
$ | type = "text/javascript" |
||
) |
Add a view script
string | $script | The `src` attribute of the `<script>` tag |
string | $type | [optional] [default "text/javascript" ] The `type` attribute of the `<script>` tag |
Definition at line 586 of file axResponse.class.php.
axResponse::addStyleSheet | ( | $ | stylesheet, |
$ | type = "text/css" , |
||
$ | media = "screen" |
||
) |
Add a view style sheet.
string | $stylesheet | The `href` attribute of the `<link>` tag |
unknown_type | $type | [optional] [default "text/css" ] The `type` attribute of the `<link>` tag |
unknown_type | $media | [optional] [default "screen" ] The `media` attribute of the `<link>` tag |
Definition at line 551 of file axResponse.class.php.
Clear all registered headers.
Definition at line 405 of file axResponse.class.php.
Erase all registered messages.
Definition at line 539 of file axResponse.class.php.
Erase all registered scripts.
Definition at line 609 of file axResponse.class.php.
Erase all registered stylesheets.
Definition at line 575 of file axResponse.class.php.
Remove all the registered variables.
Definition at line 338 of file axResponse.class.php.
axResponse::enableLayout | ( | $ | enabled = true | ) |
Enable of disable layout according to the $enabled parameter.
boolean | $enabled | [optional] [default true ] |
Definition at line 224 of file axResponse.class.php.
Get view format.
Will return null
if no format was specified.
Definition at line 184 of file axResponse.class.php.
Get view layout.
Will return null
if not layout was specified
Definition at line 205 of file axResponse.class.php.
axResponse::getMessages | ( | $ | level = null | ) |
Get all view messages, optionnaly filtered by their level.
If no level is provided, all messages from all levels will be returned in a 2 dimentionnal associative array.
string | $level | [default null ] |
Definition at line 528 of file axResponse.class.php.
Get the output callback.
Will return null
if no output callback was set.
Definition at line 442 of file axResponse.class.php.
axResponse::getVar | ( | $ | name | ) |
Get the given var.
If a filter was set using axResponse::setFilter, the filter will be applied before the data is returned. Will return null if the corresponding var is not set. Will return false if the filter fails.
false
.string | $name |
Definition at line 247 of file axResponse.class.php.
Get all the registered var.
If a filter was set using axResponse::setFilter, the filter will be applied before the data are returned. Will return false if the filter fails.
false
.Definition at line 299 of file axResponse.class.php.
Get the view name.
Will return null
if no view name was specified.
Definition at line 142 of file axResponse.class.php.
Get the view section.
Will return null
if no view section was specified.
Definition at line 163 of file axResponse.class.php.
Tells whenever a filter has been registered or not.
Definition at line 450 of file axResponse.class.php.
Tells if the layout is enabled or not.
Definition at line 233 of file axResponse.class.php.
axResponse::removeMessage | ( | $ | message | ) |
Remove a view message
string | $message |
Definition at line 512 of file axResponse.class.php.
axResponse::removeScript | ( | $ | script | ) |
Remove a script (identified by its `src`)
string | $script |
Definition at line 600 of file axResponse.class.php.
axResponse::removeStyleSheet | ( | $ | stylehseet | ) |
Remove a style sheet (identified by its `href` attribute)
string | $stylehseet |
Definition at line 566 of file axResponse.class.php.
Reset the axResponse instance to its initial state.
Definition at line 120 of file axResponse.class.php.
axResponse::setCookie | ( | $ | name, |
$ | value = "" , |
||
$ | expire = 0 , |
||
$ | path = "" , |
||
$ | domain = "" , |
||
$ | secure = false , |
||
$ | httponly = false |
||
) |
PHP setcookie alias.
Returns the current instance in case of success, false otherwise.
Definition at line 629 of file axResponse.class.php.
axResponse::setFilter | ( | array $ | filter | ) |
Set a response variable filter.
When you set a variable filter, all data you may extract with axResponse::getVar(), axResponse::__get(), or axResponse::getVars() are filtered using filter_var_array before they are returned, allowing you to set sanitize or validation filter, for instance to prevent XSS attacks.
$filter
parameter must be compliant with the $definition
parameter of PHP's filter_var_array. If the filtering ends up with an error, all variables registered in axResponse are erased and a RuntimeException will be thrown when accessing datas with axResponse::getVar(), axResponse::__get(), or axResponse::getVars().array | $filter |
Definition at line 482 of file axResponse.class.php.
axResponse::setFormat | ( | $ | format | ) |
Set view format.
srting | $format |
Definition at line 193 of file axResponse.class.php.
axResponse::setHaders | ( | array $ | headers | ) |
Set multiple headers at once.
The $headers
parameters must be an associative array which keys are header fields and values header values. Example:
$response->setHeaders(array( axResponse::HEADER_CONTENT_TYPE => 'application/octet-stream', axResponse::HEADER_CONTENT_DISCPOSITION => 'attachment; filename=download.abc' ));
If some header were previously set, they will be replaced.
array | $headers |
Definition at line 375 of file axResponse.class.php.
axResponse::setHeader | ( | $ | field, |
$ | value | ||
) |
Add an header to the header list.
If the header is already present in the list, it will be replaced.
string | $field | Should be one of axResponse::HEADER_* |
string | $value |
Definition at line 353 of file axResponse.class.php.
axResponse::setLayout | ( | $ | layout | ) |
Set view layout.
string | $layout |
Definition at line 214 of file axResponse.class.php.
axResponse::setOutputCallback | ( | $ | callback | ) |
Set a callback to be executed on the output buffer before it is sent to the browser.
Usage:
// Let's replace all <h1> tags by <h3> $response->setOutputCallback(create_function( '$buffer', 'return str_replace(array('<h1>','</h1>'),array('<h3>','</h3>'),$buffer);' ));
Callback must be a valid callback (see http://php.net/manual/en/language.pseudo-types.php), false will be returned otherwise.
callback | $callback |
Definition at line 427 of file axResponse.class.php.
axResponse::setRawCookie | ( | $ | name, |
$ | value = "" , |
||
$ | expire = 0 , |
||
$ | path = "" , |
||
$ | domain = "" , |
||
$ | secure = false , |
||
$ | httponly = false |
||
) |
PHP setrawcookie alias.
Returns the current instance in case of success, false otherwise.
Definition at line 654 of file axResponse.class.php.
axResponse::setStatus | ( | $ | http_status | ) |
Set the HTTP status http://en.wikipedia.org/wiki/List_of_HTTP_status_codes.
string | $http_status |
Definition at line 388 of file axResponse.class.php.
axResponse::setVar | ( | $ | name, |
$ | value | ||
) |
Set the given var.
string | $name | |
mixed | $value |
Definition at line 260 of file axResponse.class.php.
axResponse::setView | ( | $ | view | ) |
Set view name.
string | $view |
Definition at line 151 of file axResponse.class.php.
axResponse::setViewSection | ( | $ | section | ) |
set View section
string | $section |
Definition at line 172 of file axResponse.class.php.
axResponse::$_filter [protected] |
Definition at line 75 of file axResponse.class.php.
boolean axResponse::$_filterFlag [protected] |
Filter flag.
Tells whenever the filter has been applied and should not be applied again.
Definition at line 84 of file axResponse.class.php.
array axResponse::$_headers [protected] |
Response Headers.
Definition at line 59 of file axResponse.class.php.
boolean axResponse::$_layoutEnabled [protected] |
Enabled layout flag.
Definition at line 47 of file axResponse.class.php.
array axResponse::$_messages [protected] |
View messages.
Definition at line 90 of file axResponse.class.php.
callback axResponse::$_outputCallback [protected] |
Output callback
This callback will be executed on the response buffer (the stream sent to the browser).
Definition at line 68 of file axResponse.class.php.
array axResponse::$_scripts [protected] |
View scripts.
Definition at line 102 of file axResponse.class.php.
axResponse::$_styleSheets [protected] |
Definition at line 96 of file axResponse.class.php.
array axResponse::$_vars [protected] |
View variables.
Definition at line 53 of file axResponse.class.php.
string axResponse::$_view [protected] |
View name.
Definition at line 23 of file axResponse.class.php.
string axResponse::$_viewFormat [protected] |
View format.
Definition at line 35 of file axResponse.class.php.
string axResponse::$_viewLayout [protected] |
Layout name.
Definition at line 41 of file axResponse.class.php.
string axResponse::$_viewSection [protected] |
View section.
Definition at line 29 of file axResponse.class.php.
const axResponse::ADD_VARS = "add" |
Definition at line 694 of file axResponse.class.php.
const axResponse::HEADER_ACCEPT_RANGE = "Accept-Ranges" |
Definition at line 710 of file axResponse.class.php.
const axResponse::HEADER_AGE = "Age" |
Definition at line 711 of file axResponse.class.php.
const axResponse::HEADER_ALLOW = "Allow" |
Definition at line 712 of file axResponse.class.php.
const axResponse::HEADER_CACHE_CONTROL = "Cache-Control" |
Definition at line 713 of file axResponse.class.php.
const axResponse::HEADER_CONNECTION = "Connection" |
Definition at line 714 of file axResponse.class.php.
const axResponse::HEADER_CONTENT_DISPOSITION = "Content-Disposition" |
Definition at line 720 of file axResponse.class.php.
const axResponse::HEADER_CONTENT_ENCODING = "Content-Encoding" |
Definition at line 715 of file axResponse.class.php.
const axResponse::HEADER_CONTENT_LANGUAGE = "Content-Language" |
Definition at line 716 of file axResponse.class.php.
const axResponse::HEADER_CONTENT_LENGTH = "Content-Length" |
Definition at line 717 of file axResponse.class.php.
const axResponse::HEADER_CONTENT_LOCATION = "Content-Location" |
Definition at line 718 of file axResponse.class.php.
const axResponse::HEADER_CONTENT_MD5 = "Content-MD5" |
Definition at line 719 of file axResponse.class.php.
const axResponse::HEADER_CONTENT_RANGE = "Content-Range" |
Definition at line 721 of file axResponse.class.php.
const axResponse::HEADER_CONTENT_TYPE = "Content-Type" |
Definition at line 722 of file axResponse.class.php.
const axResponse::HEADER_DATE = "Date" |
Definition at line 723 of file axResponse.class.php.
const axResponse::HEADER_ETAG = "ETag" |
Definition at line 724 of file axResponse.class.php.
const axResponse::HEADER_EXPIRES = "Expires" |
Definition at line 725 of file axResponse.class.php.
const axResponse::HEADER_LAST_MODIFIED = "Last-Modified" |
Definition at line 726 of file axResponse.class.php.
const axResponse::HEADER_LINK = "Link" |
Definition at line 727 of file axResponse.class.php.
const axResponse::HEADER_LOCATION = "Location" |
Definition at line 728 of file axResponse.class.php.
const axResponse::HEADER_P3P = "P3P" |
Definition at line 729 of file axResponse.class.php.
const axResponse::HEADER_PRAGMA = "Pragma" |
Definition at line 730 of file axResponse.class.php.
const axResponse::HEADER_PROXY_AUTHENTICATE = "Proxy-Authenticate" |
Definition at line 731 of file axResponse.class.php.
const axResponse::HEADER_REFRESH = "Refresh" |
Definition at line 732 of file axResponse.class.php.
const axResponse::HEADER_RETRY_AFTER = "Retry-After" |
Definition at line 733 of file axResponse.class.php.
const axResponse::HEADER_SERVER = "Server" |
Definition at line 734 of file axResponse.class.php.
const axResponse::HEADER_SET_COOKIE = "Set-Cookie" |
Definition at line 735 of file axResponse.class.php.
const axResponse::HEADER_STS = "Strict-Transport-Security" |
Definition at line 736 of file axResponse.class.php.
const axResponse::HEADER_TRAILER = "Trailer" |
Definition at line 737 of file axResponse.class.php.
const axResponse::HEADER_TRANSFER_ENCODING = "Transfer-Encoding" |
Definition at line 738 of file axResponse.class.php.
const axResponse::HEADER_VARY = "Vary" |
Definition at line 739 of file axResponse.class.php.
const axResponse::HEADER_VIA = "Via" |
Definition at line 740 of file axResponse.class.php.
const axResponse::HEADER_WARNING = "Warning" |
Definition at line 741 of file axResponse.class.php.
const axResponse::HEADER_WWW_AUTHENTICATE = "WWW-Authenticate" |
Definition at line 742 of file axResponse.class.php.
const axResponse::MERGE_VARS = "merge" |
Definition at line 693 of file axResponse.class.php.
const axResponse::MESSAGE_ALERT = "alert" |
Definition at line 702 of file axResponse.class.php.
const axResponse::MESSAGE_NOTICE = "notice" |
Definition at line 700 of file axResponse.class.php.
const axResponse::MESSAGE_WARNING = "warning" |
Definition at line 701 of file axResponse.class.php.