View/Abstract.php
Zend Framework
LICENSE
This source file is subject to the new BSD license that is bundled with this package in the file LICENSE.txt. It is also available through the world-wide-web at this URL: http://framework.zend.com/license/new-bsd If you did not receive a copy of the license and are unable to obtain it through the world-wide-web, please send an email to [email protected] so we can send you a copy immediately.
- Category
- Zend
- Copyright
- Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
- License
- New BSD License
- Package
- Zend_View
- Version
- $Id: Abstract.php 24593 2012-01-05 20:35:02Z matthew $
\Zend_View_Abstract
Abstract class for Zend_View to help enforce private constructs.
- Implements
- \Zend_View_Interface
- Children
- \Zend_View
- Category
- Zend
- Copyright
- Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
- License
- New BSD License
Properties

string $_encoding = 'UTF-8'Encoding to use in escaping mechanisms; defaults to utf-8
'UTF-8'Details- Type
- string

string $_escape = 'htmlspecialchars'Callback for escaping.
'htmlspecialchars'Details- Type
- string

array $_filter = array()Stack of Zend_View_Filter names to apply as filters.
array()Details- Type
- array

array $_filterClass = array()Stack of Zend_View_Filter objects that have been loaded
array()Details- Type
- array

array $_filterLoaded = array()Map of filter => class pairs to help in determining filter class from name
array()Details- Type
- array

array $_filterLoadedDir = array()Map of filter => classfile pairs to aid in determining filter classfile
array()Details- Type
- array

array $_helperLoaded = array()Map of helper => class pairs to help in determining helper class from name
array()Details- Type
- array

array $_helperLoadedDir = array()Map of helper => classfile pairs to aid in determining helper classfile
array()Details- Type
- array

bool $_lfiProtectionOn = trueFlag indicating whether or not LFI protection for rendering view scripts is enabled
trueDetails- Type
- bool

array $_loaderTypes = array('filter', 'helper')Plugin types
array('filter', 'helper')Details- Type
- array

array $_path = array('script' => array(), 'helper' => array(), 'filter' => array())Path stack for script, helper, and filter directories.
array('script' => array(), 'helper' => array(), 'filter' => array())Details- Type
- array
Methods

__call(string $name, array $args) : stringAccesses a helper object from within a script.
If the helper class has a 'view' property, sets it with the current view object.
| Name | Type | Description |
|---|---|---|
| $name | string | The helper name. |
| $args | array | The parameters for the helper. |
| Type | Description |
|---|---|
| string | The result of the helper output. |

__construct(array $config = array()) : voidConstructor.
| Name | Type | Description |
|---|---|---|
| $config | array | Configuration key-value pairs. |

__get(string $key) : nullPrevent E_NOTICE for nonexistent values
If strictVars() is on, raises a notice.
| Name | Type | Description |
|---|---|---|
| $key | string |
| Type | Description |
|---|---|
| null |

__isset(string $key) : booleanAllows testing with empty() and isset() to work inside templates.
| Name | Type | Description |
|---|---|---|
| $key | string |
| Type | Description |
|---|---|
| boolean |

__set(string $key, mixed $val) : voidDirectly assigns a variable to the view script.
Checks first to ensure that the caller is not attempting to set a protected or private member (by checking for a prefixed underscore); if not, the public member is set; otherwise, an exception is raised.
| Name | Type | Description |
|---|---|---|
| $key | string | The variable name. |
| $val | mixed | The variable value. |
| Exception | Description |
|---|---|
| \Zend_View_Exception | if an attempt to set a private or protected member is detected |

__unset(string $key) : voidAllows unset() on object properties to work
| Name | Type | Description |
|---|---|---|
| $key | string |

_addPath(string $type, string | array $path, string $prefix = null) : voidAdds paths to the path stack in LIFO order.
Zend_View::_addPath($type, 'dirname') adds one directory to the path stack.
Zend_View::_addPath($type, $array) adds one directory for each array element value.
In the case of filter and helper paths, $prefix should be used to specify what class prefix to use with the given path.
| Name | Type | Description |
|---|---|---|
| $type | string | The path type ('script', 'helper', or 'filter'). |
| $path | string | array | The path specification. |
| $prefix | string | Class prefix to use with path (helpers and filters only) |

_addPluginPath(string $type, string $classPrefix, array $paths) : \Zend_View_AbstractAdd a prefixPath for a plugin type
| Name | Type | Description |
|---|---|---|
| $type | string | |
| $classPrefix | string | |
| $paths | array |
| Type | Description |
|---|---|
| \Zend_View_Abstract |

_filter(string $buffer) : stringApplies the filter callback to a buffer.
| Name | Type | Description |
|---|---|---|
| $buffer | string | The buffer contents. |
| Type | Description |
|---|---|
| string | The filtered buffer. |

_getPaths(string $type) : arrayReturn all paths for a given path type
| Name | Type | Description |
|---|---|---|
| $type | string | The path type ('helper', 'filter', 'script') |
| Type | Description |
|---|---|
| array |

_getPlugin(string $type, string $name) : objectRetrieve a plugin object
| Name | Type | Description |
|---|---|---|
| $type | string | |
| $name | string |
| Type | Description |
|---|---|
| object |

_getPluginPath(string $type, string $name) : string | falseGet a path to a given plugin class of a given type
| Name | Type | Description |
|---|---|---|
| $type | string | |
| $name | string |
| Type | Description |
|---|---|
| string | false |

_run() : mixedUse to include the view script in a scope that only allows public members.
| Type | Description |
|---|---|
| mixed |

_script(string $name) : voidFinds a view script from the available directories.
| Name | Type | Description |
|---|---|---|
| $name | string | The base name of the script. |

_setFilterClass(string $name, string $class, string $file) : voidRegister filter class as loaded
| Name | Type | Description |
|---|---|---|
| $name | string | |
| $class | string | |
| $file | string | path to class file |

_setHelperClass(string $name, string $class, string $file) : voidRegister helper class as loaded
| Name | Type | Description |
|---|---|---|
| $name | string | |
| $class | string | |
| $file | string | path to class file |

_setPath(string $type, string | array $path, string $classPrefix = null) : voidResets the path stack for helpers and filters.
| Name | Type | Description |
|---|---|---|
| $type | string | The path type ('helper' or 'filter'). |
| $path | string | array | The directory (-ies) to set as the path. |
| $classPrefix | string | Class prefix to apply to elements of $path |

addBasePath(string $path, $classPrefix = 'Zend_View') : \Zend_View_AbstractGiven a base path, add script, helper, and filter paths relative to it
Assumes a directory structure of:
basePath/
scripts/
helpers/
filters/
| Name | Type | Description |
|---|---|---|
| $path | string | |
| $classPrefix |
| Type | Description |
|---|---|
| \Zend_View_Abstract |

addFilter(string | array $name) : \Zend_View_AbstractAdd one or more filters to the stack in FIFO order.
| Name | Type | Description |
|---|---|---|
| $name | string | array | One or more filters to add. |
| Type | Description |
|---|---|
| \Zend_View_Abstract |

addFilterPath(string | array $path, string $classPrefix = 'Zend_View_Filter_') : \Zend_View_AbstractAdds to the stack of filter paths in LIFO order.
| Name | Type | Description |
|---|---|---|
| $path | string | array | The directory (-ies) to add. |
| $classPrefix | string | Class prefix to use with classes in this directory; defaults to Zend_View_Filter |
| Type | Description |
|---|---|
| \Zend_View_Abstract |

addHelperPath(string | array $path, string $classPrefix = 'Zend_View_Helper_') : \Zend_View_AbstractAdds to the stack of helper paths in LIFO order.
| Name | Type | Description |
|---|---|---|
| $path | string | array | The directory (-ies) to add. |
| $classPrefix | string | Class prefix to use with classes in this directory; defaults to Zend_View_Helper |
| Type | Description |
|---|---|
| \Zend_View_Abstract |

addScriptPath(string | array $path) : \Zend_View_AbstractAdds to the stack of view script paths in LIFO order.
| Name | Type | Description |
|---|---|---|
| $path | string | array | The directory (-ies) to add. |
| Type | Description |
|---|---|
| \Zend_View_Abstract |

assign(string | array $spec, mixed $value = null) : \Zend_View_AbstractAssigns variables to the view script via differing strategies.
Zend_View::assign('name', $value) assigns a variable called 'name' with the corresponding $value.
Zend_View::assign($array) assigns the array keys as variable names (with the corresponding array values).
| Name | Type | Description |
|---|---|---|
| $spec | string | array | The assignment strategy to use. |
| $value | mixed | (Optional) If assigning a named variable, use this as the value. |
| Type | Description |
|---|---|
| \Zend_View_Abstract | Fluent interface |
| Exception | Description |
|---|---|
| \Zend_View_Exception | if $spec is neither a string nor an array, or if an attempt to set a private or protected member is detected |
- See
- \global\__set()

escape(mixed $var) : mixedEscapes a value for output in a view script.
If escaping mechanism is one of htmlspecialchars or htmlentities, uses $_encoding setting.
| Name | Type | Description |
|---|---|---|
| $var | mixed | The output to escape. |
| Type | Description |
|---|---|
| mixed | The escaped value. |

getEngine() : \Zend_View_AbstractReturn the template engine object
Returns the object instance, as it is its own template engine
| Type | Description |
|---|---|
| \Zend_View_Abstract |

getFilter(string $name) : objectGet a filter object by name
| Name | Type | Description |
|---|---|---|
| $name | string |
| Type | Description |
|---|---|
| object |

getFilterPath(string $name) : string | falseGet full path to a filter class file specified by $name
| Name | Type | Description |
|---|---|---|
| $name | string |
| Type | Description |
|---|---|
| string | false | False on failure, path on success |

getFilterPaths() : arrayReturns an array of all currently set filter paths
| Type | Description |
|---|---|
| array |

getFilters() : arrayReturn array of all currently active filters
Only returns those that have already been instantiated.
| Type | Description |
|---|---|
| array |

getHelper(string $name) : objectGet a helper by name
| Name | Type | Description |
|---|---|---|
| $name | string |
| Type | Description |
|---|---|
| object |

getHelperPath(string $name) : string | falseGet full path to a helper class file specified by $name
| Name | Type | Description |
|---|---|---|
| $name | string |
| Type | Description |
|---|---|
| string | false | False on failure, path on success |

getHelperPaths() : arrayReturns an array of all currently set helper paths
| Type | Description |
|---|---|
| array |

getHelpers() : arrayGet array of all active helpers
Only returns those that have already been instantiated.
| Type | Description |
|---|---|
| array |

getPluginLoader(string $type) : \Zend_Loader_PluginLoaderRetrieve plugin loader for a specific plugin type
| Name | Type | Description |
|---|---|---|
| $type | string |
| Type | Description |
|---|---|
| \Zend_Loader_PluginLoader |

getScriptPath(string $name) : false | stringReturn full path to a view script specified by $name
| Name | Type | Description |
|---|---|---|
| $name | string |
| Type | Description |
|---|---|
| false | string | False if script not found |
| Exception | Description |
|---|---|
| \Zend_View_Exception | if no script directory set |

getScriptPaths() : arrayReturns an array of all currently set script paths
| Type | Description |
|---|---|
| array |

getVars() : arrayReturn list of all assigned variables
Returns all public properties of the object. Reflection is not used here as testing reflection properties for visibility is buggy.
| Type | Description |
|---|---|
| array |

init() : voidAllow custom object initialization when extending Zend_View_Abstract or Zend_View
Triggered by the constructor as its final action.

registerHelper(\Zend_View_Helper_Abstract | object $helper, string $name) : \Zend_View_AbstractRegisters a helper object, bypassing plugin loader
| Name | Type | Description |
|---|---|---|
| $helper | \Zend_View_Helper_Abstract | object | |
| $name | string |
| Type | Description |
|---|---|
| \Zend_View_Abstract |
| Exception | Description |
|---|---|
| \Zend_View_Exception |

render(string $name) : stringProcesses a view script and returns the output.
| Name | Type | Description |
|---|---|---|
| $name | string | The script name to process. |
| Type | Description |
|---|---|
| string | The script output. |

setBasePath(string $path, $classPrefix = 'Zend_View') : \Zend_View_AbstractGiven a base path, sets the script, helper, and filter paths relative to it
Assumes a directory structure of:
basePath/
scripts/
helpers/
filters/
| Name | Type | Description |
|---|---|---|
| $path | string | |
| $classPrefix |
| Type | Description |
|---|---|
| \Zend_View_Abstract |

setEncoding(string $encoding) : \Zend_View_AbstractSet encoding to use with htmlentities() and htmlspecialchars()
| Name | Type | Description |
|---|---|---|
| $encoding | string |
| Type | Description |
|---|---|
| \Zend_View_Abstract |

setEscape(mixed $spec) : \Zend_View_AbstractSets the _escape() callback.
| Name | Type | Description |
|---|---|---|
| $spec | mixed | The callback for _escape() to use. |
| Type | Description |
|---|---|
| \Zend_View_Abstract |

setFilter(string | array $name) : \Zend_View_AbstractResets the filter stack.
To clear all filters, use Zend_View::setFilter(null).
| Name | Type | Description |
|---|---|---|
| $name | string | array | One or more filters to set. |
| Type | Description |
|---|---|
| \Zend_View_Abstract |

setFilterPath(string | array $path, string $classPrefix = 'Zend_View_Filter_') : \Zend_View_AbstractResets the stack of filter paths.
To clear all paths, use Zend_View::setFilterPath(null).
| Name | Type | Description |
|---|---|---|
| $path | string | array | The directory (-ies) to set as the path. |
| $classPrefix | string | The class prefix to apply to all elements in $path; defaults to Zend_View_Filter |
| Type | Description |
|---|---|
| \Zend_View_Abstract |

setHelperPath(string | array $path, string $classPrefix = 'Zend_View_Helper_') : \Zend_View_AbstractResets the stack of helper paths.
To clear all paths, use Zend_View::setHelperPath(null).
| Name | Type | Description |
|---|---|---|
| $path | string | array | The directory (-ies) to set as the path. |
| $classPrefix | string | The class prefix to apply to all elements in $path; defaults to Zend_View_Helper |
| Type | Description |
|---|---|
| \Zend_View_Abstract |

setLfiProtection(bool $flag) : \Zend_View_AbstractSet LFI protection flag
| Name | Type | Description |
|---|---|---|
| $flag | bool |
| Type | Description |
|---|---|
| \Zend_View_Abstract |

setPluginLoader(\Zend_Loader_PluginLoader $loader, string $type) : \Zend_View_AbstractSet plugin loader for a particular plugin type
| Name | Type | Description |
|---|---|---|
| $loader | \Zend_Loader_PluginLoader | |
| $type | string |
| Type | Description |
|---|---|
| \Zend_View_Abstract |

setScriptPath(string | array $path) : \Zend_View_AbstractResets the stack of view script paths.
To clear all paths, use Zend_View::setScriptPath(null).
| Name | Type | Description |
|---|---|---|
| $path | string | array | The directory (-ies) to set as the path. |
| Type | Description |
|---|---|
| \Zend_View_Abstract |

strictVars(boolean $flag = true) : \Zend_View_AbstractEnable or disable strict vars
If strict variables are enabled, __get() will raise a notice when a variable is not defined.
Use in conjunction with the declareVars() helper to enforce strict variable handling in your view scripts.
| Name | Type | Description |
|---|---|---|
| $flag | boolean |
| Type | Description |
|---|---|
| \Zend_View_Abstract |