jZone
in package
jZone is a representation of a zone in an response content, in a html page.
A user zone should inherits from jZone. jZone provide a cache mecanism.
Tags
Table of Contents
- $_cacheTimeout : int
- cache timeout (seconds).
- $_cancelCache : bool
- When the cache system is activated, says if the cache should be generated or not you set it to false in _createContent or _prepareTpl, in specific case.
- $_params : array<string|int, mixed>
- list of zone parameters.
- $_tpl : jTpl
- the jtpl object created automatically by jZone if you set up _tplname you can use it in _prepareTpl.
- $_tplname : string
- template selector If you want to use a template for your zone, set its name in this property in your zone, and override _prepareTpl. Else, keep it to empty string, and override _createContent.
- $_tplOutputType : string
- says the type of the output of the template, in the case of the result of the zone is not used in a response in the same output type.
- $_useCache : bool
- If we're using cache on this zone You should override it in your class if you want activate the cache.
- __construct() : mixed
- constructor.
- clear() : mixed
- clear a specific cache of a zone.
- clearAll() : mixed
- clear all zone cache or all cache of a specific zone.
- clearCache() : mixed
- Delete the cache of the current zone.
- get() : string
- get the content of a zone.
- getContent() : string
- get the zone content Return the cache content if it is activated and if it's exists, or call _createContent.
- param() : mixed
- gets the value of a parameter, if defined. Returns the default value instead.
- _createContent() : string
- create the content of the zone by default, it uses a template, and so prepare a jTpl object to use in _prepareTpl.
- _execMetaFunc() : mixed
- _generateContentAndCatchMetaCalls() : array<string|int, mixed>
- When the zone generated content is in cache, the template content is not executed, so zones called in the template (via the `{zone}` plugin) are not called. In this case, meta plugin of their templates are not processed.
- _prepareTpl() : mixed
- override this method if you want do additionnal thing on the template object Example : do access to a dao object.. Note : the template object is in the _tpl property.
- getCacheId() : array<string|int, mixed>
- It should returns a list of values that are used for the cache Id.
- _callZone() : mixed
- instancy a zone object, and call one of its methods.
- _getCacheFiles() : array<string|int, mixed>
- Get the list of cache filenames.
Properties
$_cacheTimeout
cache timeout (seconds).
protected
int
$_cacheTimeout
= 0
set to 0 if you want to delete cache manually.
Tags
$_cancelCache
When the cache system is activated, says if the cache should be generated or not you set it to false in _createContent or _prepareTpl, in specific case.
protected
bool
$_cancelCache
= \false
Tags
$_params
list of zone parameters.
protected
array<string|int, mixed>
$_params
Tags
$_tpl
the jtpl object created automatically by jZone if you set up _tplname you can use it in _prepareTpl.
protected
jTpl
$_tpl
Tags
$_tplname
template selector If you want to use a template for your zone, set its name in this property in your zone, and override _prepareTpl. Else, keep it to empty string, and override _createContent.
protected
string
$_tplname
= ''
Tags
$_tplOutputType
says the type of the output of the template, in the case of the result of the zone is not used in a response in the same output type.
protected
string
$_tplOutputType
= ''
For example, the output type of a ajax response is text, but the template can contains html, so the template should be treated as html content, so you should put 'html' here. If empty, the output type will be the output type of the current response.
Tags
$_useCache
If we're using cache on this zone You should override it in your class if you want activate the cache.
protected
bool
$_useCache
= \false
Tags
Methods
__construct()
constructor.
public
__construct([mixed $params = array() ]) : mixed
Parameters
- $params : mixed = array()
Tags
Return values
mixed —clear()
clear a specific cache of a zone.
public
static clear(string $name[, array<string|int, mixed> $params = array() ]) : mixed
Parameters
- $name : string
-
zone selector
- $params : array<string|int, mixed> = array()
-
parameters for the zone
Tags
Return values
mixed —clearAll()
clear all zone cache or all cache of a specific zone.
public
static clearAll([string $name = '' ]) : mixed
Parameters
- $name : string = ''
-
zone selector
Tags
Return values
mixed —clearCache()
Delete the cache of the current zone.
public
clearCache() : mixed
Tags
Return values
mixed —get()
get the content of a zone.
public
static get(string $name[, array<string|int, mixed> $params = array() ]) : string
Parameters
- $name : string
-
zone selector
- $params : array<string|int, mixed> = array()
-
parameters for the zone
Tags
Return values
string —the generated content of the zone
getContent()
get the zone content Return the cache content if it is activated and if it's exists, or call _createContent.
public
getContent() : string
Tags
Return values
string —zone content
param()
gets the value of a parameter, if defined. Returns the default value instead.
public
param(string $paramName[, mixed $defaultValue = null ]) : mixed
Parameters
- $paramName : string
-
the parameter name
- $defaultValue : mixed = null
-
the parameter default value
Tags
Return values
mixed —the param value
_createContent()
create the content of the zone by default, it uses a template, and so prepare a jTpl object to use in _prepareTpl.
protected
_createContent() : string
zone parameters are automatically assigned in the template If you don't want a template, override it in your class.
Tags
Return values
string —generated content
_execMetaFunc()
protected
_execMetaFunc(mixed $resp, mixed $_file) : mixed
Parameters
- $resp : mixed
- $_file : mixed
Tags
Return values
mixed —_generateContentAndCatchMetaCalls()
When the zone generated content is in cache, the template content is not executed, so zones called in the template (via the `{zone}` plugin) are not called. In this case, meta plugin of their templates are not processed.
protected
_generateContentAndCatchMetaCalls() : array<string|int, mixed>
In order to process meta of children zone, we catch all calls of methods of the global response object (did by the meta plugins), to generate a function that will do same calls when getting the cache content of the zone.
FIXME: see if a better solution could be the creating of a jZone::meta() that will do a jTpl::meta() of its template, and jZone::meta() would be added into the meta content function of the generated template by the '{zone}' plugin.
Tags
Return values
array<string|int, mixed> —_prepareTpl()
override this method if you want do additionnal thing on the template object Example : do access to a dao object.. Note : the template object is in the _tpl property.
protected
_prepareTpl() : mixed
Tags
Return values
mixed —getCacheId()
It should returns a list of values that are used for the cache Id.
protected
getCacheId() : array<string|int, mixed>
By default, it returns all zone parameters. But some parameters may have values (like some object properties) that are not used for the zone and unfortunately which changed often. The Cache id is then not 'stable' and the cache system may generate a cache at each call.
So you can redefine this method to return only values that should be used as cache ID (I.e. which determines the uniqueness of the zone content)
Tags
Return values
array<string|int, mixed> —list of values that are used for the cache Id
_callZone()
instancy a zone object, and call one of its methods.
private
static _callZone(string $name, string $method, array<string|int, mixed> &$params) : mixed
Parameters
- $name : string
-
zone selector
- $method : string
-
method name
- $params : array<string|int, mixed>
-
arguments for the method
Tags
Return values
mixed —the result returned by the method
_getCacheFiles()
Get the list of cache filenames.
private
_getCacheFiles([mixed $forCurrentResponse = true ]) : array<string|int, mixed>
Parameters
- $forCurrentResponse : mixed = true
Tags
Return values
array<string|int, mixed> —list of filenames