Axiom (v1.2.0)

A lightweight PHP framework
axResponse Class Reference

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.

Detailed Description

Response Class.

Todo:
axResponse long description
Author:
Delespierre
License:
http://www.gnu.org/licenses/lgpl.html Lesser General Public Licence version 3

Definition at line 17 of file axResponse.class.php.


Constructor & Destructor Documentation

Constructor.

Definition at line 107 of file axResponse.class.php.


Member Function Documentation

axResponse::__get ( key)

__get implementation

See also:
axResponse::getVar()
Parameters:
string$key
Returns:
mixed

Definition at line 273 of file axResponse.class.php.

axResponse::__set ( key,
value 
)

__set implementation

See also:
axResponse::setVar()
Parameters:
string$key
mixed$value
Returns:
void

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.

Exceptions:
RuntimeExceptionIf the filter fails
Returns:
boolan

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.

Parameters:
array$collection
string$method[optional] [default axResponse::MERGE_VARS] Possible values are axResponse::MERGE_VARS or axResponse::ADD_VARS
Returns:
axResponse

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.

Parameters:
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
Returns:
axResponse

Definition at line 499 of file axResponse.class.php.

axResponse::addScript ( script,
type = "text/javascript" 
)

Add a view script

Parameters:
string$scriptThe `src` attribute of the `<script>` tag
string$type[optional] [default "text/javascript"] The `type` attribute of the `<script>` tag
Returns:
axResponse

Definition at line 586 of file axResponse.class.php.

axResponse::addStyleSheet ( stylesheet,
type = "text/css",
media = "screen" 
)

Add a view style sheet.

Parameters:
string$stylesheetThe `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
Returns:
axResponse

Definition at line 551 of file axResponse.class.php.

Clear all registered headers.

Returns:
axResponse

Definition at line 405 of file axResponse.class.php.

Erase all registered messages.

Returns:
axResponse

Definition at line 539 of file axResponse.class.php.

Erase all registered scripts.

Returns:
axResponse

Definition at line 609 of file axResponse.class.php.

Erase all registered stylesheets.

Returns:
axResponse

Definition at line 575 of file axResponse.class.php.

Remove all the registered variables.

Returns:
axResponse

Definition at line 338 of file axResponse.class.php.

axResponse::enableLayout ( enabled = true)

Enable of disable layout according to the $enabled parameter.

Parameters:
boolean$enabled[optional] [default true]
Returns:
axResponse

Definition at line 224 of file axResponse.class.php.

Get the registered filter.

See also:
http://php.net/manual/en/function.filter-var-array.php
Returns:
array

Definition at line 460 of file axResponse.class.php.

Get view format.

Will return null if no format was specified.

Returns:
string

Definition at line 184 of file axResponse.class.php.

Get the headers list.

Returns:
array

Definition at line 397 of file axResponse.class.php.

Get view layout.

Will return null if not layout was specified

Returns:
string

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.

Parameters:
string$level[default null]
Returns:
array

Definition at line 528 of file axResponse.class.php.

Get the output callback.

Will return null if no output callback was set.

Returns:
callback

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.

Warning:
You will loose all vars that doesn't pass the filter, they'll be set to false.
Parameters:
string$name
Returns:
mixed

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.

Warning:
You will loose all vars that doesn't pass the filter, they'll be set to false.
See also:
http://www.php.net/manual/en/function.filter-var-array.php
Returns:
array

Definition at line 299 of file axResponse.class.php.

Get the view name.

Will return null if no view name was specified.

Returns:
string

Definition at line 142 of file axResponse.class.php.

Get the view section.

Will return null if no view section was specified.

Returns:
string

Definition at line 163 of file axResponse.class.php.

Tells whenever a filter has been registered or not.

Returns:
boolean

Definition at line 450 of file axResponse.class.php.

Tells if the layout is enabled or not.

Returns:
boolean

Definition at line 233 of file axResponse.class.php.

axResponse::removeMessage ( message)

Remove a view message

Parameters:
string$message
Returns:
axResponse

Definition at line 512 of file axResponse.class.php.

axResponse::removeScript ( script)

Remove a script (identified by its `src`)

See also:
axResponse::addScript
Parameters:
string$script
Returns:
axResponse

Definition at line 600 of file axResponse.class.php.

axResponse::removeStyleSheet ( stylehseet)

Remove a style sheet (identified by its `href` attribute)

See also:
axResponse::addStyleSheet
Parameters:
string$stylehseet
Returns:
axResponse

Definition at line 566 of file axResponse.class.php.

Reset the axResponse instance to its initial state.

Returns:
void

Definition at line 120 of file axResponse.class.php.

axResponse::setCookie ( name,
value = "",
expire = 0,
path = "",
domain = "",
secure = false,
httponly = false 
)
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.

Warning:
The $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().
Note:
The filter will be applied on read so your changes won't take effects until you extract response data with axResponse::getVar(), axResponse::getVars() or with the magic method axResponse::__get().
See also:
http://php.net/manual/en/function.filter-var-array.php
Parameters:
array$filter
Returns:
axResponse

Definition at line 482 of file axResponse.class.php.

axResponse::setFormat ( format)

Set view format.

Parameters:
srting$format
Returns:
axResponse

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.

See also:
axResponse::addHeader()
Parameters:
array$headers
Returns:
axResponse

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.

Note:
HTTP Response header fields have been presets as axResponse constants.
Parameters:
string$fieldShould be one of axResponse::HEADER_*
string$value
Returns:
axResponse

Definition at line 353 of file axResponse.class.php.

axResponse::setLayout ( layout)

Set view layout.

Parameters:
string$layout
Returns:
axResponse

Definition at line 214 of file axResponse.class.php.

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.

Parameters:
callback$callback
Returns:
axResponse

Definition at line 427 of file axResponse.class.php.

axResponse::setRawCookie ( name,
value = "",
expire = 0,
path = "",
domain = "",
secure = false,
httponly = false 
)
axResponse::setStatus ( http_status)

Set the HTTP status http://en.wikipedia.org/wiki/List_of_HTTP_status_codes.

Parameters:
string$http_status
Returns:
axResponse

Definition at line 388 of file axResponse.class.php.

axResponse::setVar ( name,
value 
)

Set the given var.

Parameters:
string$name
mixed$value
Returns:
axResponse

Definition at line 260 of file axResponse.class.php.

axResponse::setView ( view)

Set view name.

Parameters:
string$view
Returns:
axResponse

Definition at line 151 of file axResponse.class.php.

set View section

Parameters:
string$section
Returns:
axResponse

Definition at line 172 of file axResponse.class.php.


Field Documentation

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.


The documentation for this class was generated from the following file:
 All Data Structures Files Functions Variables