*Zend_View_Helper_Placeholder*
By allowing templates within the Composite View tree (i.e. nested render() calls, partials etc.) access a central object which all View objects may access as a central Registry, it becomes possible for nested templates, irrespective of nest depth, to influence their top-level decorating Layout, or subsequently rendered templates, by setting values these may later refer to.
All values are stored in array objects. This enables Placeholders to maintain an indexed set of values, where the order of inclusion at a rendering point is determined by this index. Because it implements ArrayObject, any PHP array sorting function may be used to sort the placeholder values.
This strategy is built into a set of a pre-defined Placeholders for the <head> element of HTML documents in the proposed Zend_View_Helper_Head* helpers. More similar helpers may be proposed if their utility proves valuable. Their purpose is primarily to offer specialised usage of the basic Placeholder class using Proxies which are capable of outputting valid XHTML/HTML using the values set by the template authors, and optionally specific to a defined Doctype.
{code:php}
/**
* Container for placeholder values
*/
class Zend_View_Helper_Placeholder_Container extends ArrayObject
{
const SET = 'set';
const APPEND = 'append';
protected $_prefix = '';
protected $_postfix = '';
protected $_separator = '';
protected $_captureLock = false;
protected $_captureType;
/**
* Set a single value
*
* @param mixed $value
* @return void
*/
public function set($value)
{
$this->exchangeArray(array($value));
}
/**
* Retrieve container value
*
* If single element registered, returns that element; otherwise,
* serializes to array.
*
* @return mixed
*/
public function getValue()
{
if (1 == count($this)) {
return $this[0];
}
return $this->getArrayCopy();
}
/**
* Set prefix for __toString() serialization
*
* @param string $prefix
* @return Zend_View_Helper_Placeholder_Container
*/
public function setPrefix($prefix)
{}
/**
* Retrieve prefix
*
* @return string
*/
public function getPrefix()
{}
/**
* Set postfix for __toString() serialization
*
* @param string $postfix
* @return Zend_View_Helper_Placeholder_Container
*/
public function setPostfix($postfix)
{}
/**
* Retrieve postfix
*
* @return string
*/
public function getPostfix()
{}
/**
* Set separator for __toString() serialization
*
* Used to implode elements in container
*
* @param string $separator
* @return Zend_View_Helper_Placeholder_Container
*/
public function setSeparator($separator)
{}
/**
* Retrieve separator
*
* @return string
*/
public function getSeparator()
{}
/**
* Start capturing content to push into placeholder
*
* @param int $type How to capture content into placeholder; append or set
* @return void
* @throws Zend_View_Helper_Placeholder_Exception if nested captures detected
*/
public function captureStart($type = Zend_View_Helper_Placeholder_Container::APPEND)
{
if ($this->_captureLock) {
throw new Zend_View_Helper_Placeholder_Exception('Cannot nest placeholder captures for the same placeholder');
}
$this->_captureLock = true;
$this->_captureType = $type;
ob_start();
}
/**
* End content capture
*
* @return void
*/
public function captureEnd()
{
$data = ob_get_flush();
$this->_captureLock = false;
switch ($this->_captureType) {
case self::SET:
$this->exchangeArray(array($data));
break;
case self::APPEND:
default:
$this[] = $data;
break;
}
}
/**
* Serialize object to string
*
* @return string
*/
public function __toString()
{
$items = $this->getArrayCopy();
$return = $this->getPrefix()
. implode($this->getSeparator(), $items)
. $this->getPostfix();
return $return;
}
}
/**
* Helper for passing data between otherwise segregated Views. It's called
* Placeholder to make its typical usage obvious, but can be used just as easily
* for non-Placeholder things. That said, the support for this is only
* guaranteed to effect subsequently rendered templates, and of course Layouts.
* This class is utilised by a number of specialised helpers such as
* Zend_View_Helper_HeadTitle
*/
class Zend_View_Helper_Placeholder
{
/**
* @var Zend_View_Interface
*/
public $view;
/**
* Placeholder items
* @var array
*/
protected $_items = array();
/**
* Set view
*
* @param Zend_View_Interface $view
* @return void
*/
public function setView(Zend_View_Interface $view)
{
$this->view = $view;
}
/**
* Placeholder helper
*
* @param string $name
* @return Zend_View_Helper_Placeholder_Container
*/
public function placeholder($name)
{
$name = (string) $name;
if (!isset($this->_items[$name])) {
$this->_items[$name] = new Zend_View_Helper_Placeholder_Container(array());
}
return $this->_items[$name];
}
}
{code}
*Zend_View_Helper_HeadTitle*
A small helper delegating to Zend_View_Helper_Placeholder which allows the user to utilise a default Placeholder for the express purpose of defining a page title for insertion into a Layout head element.
{code:php}
/**
* Helper to insert or append <title> tags to the ZEND_HEAD Placeholder
*/
class Zend_View_Helper_HeadTitle
{
/**
* Instance of parent Zend_View object
*
* @var Zend_View_Abstract
*/
public $view = null
/**
* The default Zend_View_Helper_Placeholder instance
*
* @var Zend_View_Helper_Placeholder
*/
protected $_placeholder = null;
/**
* Constants
*/
const HEADTITLE_NAMESPACE = 'ZEND_HEAD_TITLE';
/**
* Constructor; assigns a Zend_View_Helper_Placeholder object.
*/
public function __construct()
{}
/**
* Return self for further in-object calls
*
* @return Zend_View_Helper_Placeholder_Container
*/
public function headTitle($value = null)
{}
/**
* Set view object
*
* @param Zend_View_Interface $view
* @return Zend_View_Helper_HeadTitle
*/
public function setView(Zend_View_Interface $view)
{}
}
{code}
*Zend_View_Helper_HeadMeta*
A small helper delegating to Zend_View_Helper_Placeholder which allows the user to utilise a default Placeholder for the express purpose of defining page <meta> tags for insertion into a Layout head element.
{code:php}
/**
* Helper to add a <meta> tag value to a head->meta Placeholder
*
* @category Zend
* @package Zend_View
* @subpackage Helper
* @copyright Copyright (c) 2007 Pádraic Brady
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_View_Helper_HeadMeta
{
/**
* Instance of parent Zend_View object
*
* @var Zend_View_Abstract
*/
public $view = null;
/**
* The default Zend_View_Helper_Placeholder instance
*
* @var Zend_View_Helper_Placeholder
*/
protected $_placeholder = null;
/**
* Constants
*/
const HEADMETA_NAMESPACE = 'ZEND_HEAD_META';
/**
* Append a Head <meta> value if a parameter and
* return self for further in-object calls
*
* @return Zend_View_Helper_Placeholder_Container
*/
public function headMeta($value = null)
{}
/**
* Set view object
*
* @param Zend_View_Interface $view
* @return Zend_View_Helper_HeadTitle
*/
public function setView(Zend_View_Interface $view)
{}
}
{code}
*Zend_View_Helper_HeadStyle*
A small helper delegating to Zend_View_Helper_Placeholder which allows the user to utilise a default Placeholder for the express purpose of defining page <style> tags for insertion into a Layout head element.
{code:php}
/**
* Helper to add a <style> tag value to a head->style Placeholder
*/
class Zend_View_Helper_HeadStyle
{
/**
* Instance of parent Zend_View object
*
* @var Zend_View_Abstract
*/
public $view = null;
/**
* The default Zend_View_Helper_Placeholder instance
*
* @var Zend_View_Helper_Placeholder
*/
protected $_placeholder = null;
/**
* Constants
*/
const HEADSTYLE_NAMESPACE = 'ZEND_HEAD_STYLE';
/**
* Append a Head <meta> value if a parameter and
* return self for further in-object calls
*
* @return Zend_View_Helper_Placeholder_Container
*/
public function headStyle($value = null)
{}
/**
* Set view object
*
* @param Zend_View_Interface $view
* @return Zend_View_Helper_HeadStyle
*/
public function setView(Zend_View_Interface $view)
{}
}
{code}
*Zend_View_Helper_HeadScript*
Include a Script file, or code block with a <head> element. Can avail of indexation to ensure Scripts are included in a preferred order.
{code:php}
/**
* Helper to insert or append <script> tags to the head->script Placeholder
*/
class Zend_View_Helper_HeadScript
{
/**
* Instance of parent Zend_View object
*
* @var Zend_View_Abstract
*/
public $view = null;
/**
* The default Zend_View_Helper_Placeholder instance
*
* @var Zend_View_Helper_Placeholder
*/
protected $_placeholder = null;
/**
* Constants
*/
const HEADSCRIPT_NAMESPACE = 'ZEND_HEAD_SCRIPT';
/**
* Return self for further in-object calls
*
* @return Zend_View_Helper_Placeholder_Container
*/
public function headScript($file = null, $type = null, $index = null)
{}
/**
* Set view object
*
* @param Zend_View_Interface $view
* @return Zend_View_Helper_HeadScript
*/
public function setView(Zend_View_Interface $view)
{}
}
{code}
*Zend_View_Helper_Link*
Add a Link element based on an array of attributes to be added to the <head> section of a template or layout. Although this can also handle style sheets, it may prove more useful to use the HeadStyle View Helper to segregate styles from other types of relationship links.
{code:php}
/**
* Helper to add a <link> tag value to a head->link Placeholder
*/
class Zend_View_Helper_HeadLink
{
/**
* Instance of parent Zend_View object
*
* @var Zend_View_Abstract
*/
public $view = null;
/**
* The default Zend_View_Helper_Placeholder instance
*
* @var Zend_View_Helper_Placeholder
*/
protected $_placeholder = null;
/**
* Attributes common to <link> elements
*
* @var string
*/
protected $_attributes = array('href', 'charset', 'hreflang', 'media', 'rel', 'rev', 'target', 'type', 'id', 'class', 'title', 'style', 'dir', 'lang', 'xml:lang');
/**
* Constants
*/
const HEADLINK_NAMESPACE = 'ZEND_HEAD_LINK';
/**
* Set the Head <link> value if a parameter and
* return self for further in-object call
*
* @param array $attributes
* @return Zend_View_Helper_Placeholder_Container
*/
public function headLink(array $attributes = null)
{}
/**
* Set view object
*
* @param Zend_View_Interface $view
* @return Zend_View_Helper_HeadLink
*/
public function setView(Zend_View_Interface $view)
{}
}
{code}
*Zend_View_Helper_Doctype*
Obtain the Doctype string based on the Standard name for HTML, XHTML, MathML and SVG.
{code:php}
/**
* Helper to obtain a doctype declaration based on the $standard parameter
* which reflects the full name of the standard including version and context
*/
class Zend_View_Helper_Doctype
{
public function doctype($standard = 'XHTML 1.0 Transitional')
{}
protected function _doctypeXhtml($standard)
{}
protected function _doctypeHtml($standard)
{}
protected function _doctypeMath($standard)
{}
protected function _doctypeSvg($standard)
{}
}
{code}
{zone-data}
{zone-template-instance}