📄 displaygroup.php
字号:
<?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 license@zend.com so we can send you a copy immediately. * * @category Zend * @package Zend_Form * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License *//** * Zend_Form_DisplayGroup * * @category Zend * @package Zend_Form * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License * @version $Id: DisplayGroup.php 8982 2008-03-21 21:13:32Z matthew $ */class Zend_Form_DisplayGroup implements Iterator,Countable{ /** * Group attributes * @var array */ protected $_attribs = array(); /** * Display group decorators * @var array */ protected $_decorators = array(); /** * Description * @var string */ protected $_description; /** * Should we disable loading the default decorators? * @var bool */ protected $_disableLoadDefaultDecorators = false; /** * Element order * @var array */ protected $_elementOrder = array(); /** * Elements * @var array */ protected $_elements = array(); /** * Whether or not a new element has been added to the group * @var bool */ protected $_groupUpdated = false; /** * Plugin loader for decorators * @var Zend_Loader_PluginLoader */ protected $_loader; /** * Group name * @var string */ protected $_name; /** * Group order * @var int */ protected $_order; /** * @var Zend_Translate */ protected $_translator; /** * Is translation disabled? * @var bool */ protected $_translatorDisabled = false; /** * @var Zend_View_Interface */ protected $_view; /** * Constructor * * @param string $name * @param Zend_Loader_PluginLoader $loader * @param array|Zend_Config $options * @return void */ public function __construct($name, Zend_Loader_PluginLoader $loader, $options = null) { $this->setName($name); $this->setPluginLoader($loader); if (is_array($options)) { $this->setOptions($options); } elseif ($options instanceof Zend_Config) { $this->setConfig($options); } // Extensions... $this->init(); $this->loadDefaultDecorators(); } /** * Initialize object; used by extending classes * * @return void */ public function init() { } /** * Set options * * @param array $options * @return Zend_Form_DisplayGroup */ public function setOptions(array $options) { $forbidden = array( 'Options', 'Config', 'PluginLoader', 'View', 'Translator', 'Attrib' ); foreach ($options as $key => $value) { $normalized = ucfirst($key); if (in_array($normalized, $forbidden)) { continue; } $method = 'set' . $normalized; if (method_exists($this, $method)) { $this->$method($value); } else { $this->setAttrib($key, $value); } } return $this; } /** * Set options from config object * * @param Zend_Config $config * @return Zend_Form_DisplayGroup */ public function setConfig(Zend_Config $config) { return $this->setOptions($config->toArray()); } /** * Set group attribute * * @param string $key * @param mixed $value * @return Zend_Form_DisplayGroup */ public function setAttrib($key, $value) { $key = (string) $key; $this->_attribs[$key] = $value; return $this; } /** * Add multiple form attributes at once * * @param array $attribs * @return Zend_Form_DisplayGroup */ public function addAttribs(array $attribs) { foreach ($attribs as $key => $value) { $this->setAttrib($key, $value); } return $this; } /** * Set multiple form attributes at once * * Overwrites any previously set attributes. * * @param array $attribs * @return Zend_Form_DisplayGroup */ public function setAttribs(array $attribs) { $this->clearAttribs(); return $this->addAttribs($attribs); } /** * Retrieve a single form attribute * * @param string $key * @return mixed */ public function getAttrib($key) { $key = (string) $key; if (!isset($this->_attribs[$key])) { return null; } return $this->_attribs[$key]; } /** * Retrieve all form attributes/metadata * * @return array */ public function getAttribs() { return $this->_attribs; } /** * Remove attribute * * @param string $key * @return bool */ public function removeAttrib($key) { if (array_key_exists($key, $this->_attribs)) { unset($this->_attribs[$key]); return true; } return false; } /** * Clear all form attributes * * @return Zend_Form */ public function clearAttribs() { $this->_attribs = array(); return $this; } /** * Filter a name to only allow valid variable characters * * @param string $value * @return string */ public function filterName($value) { return preg_replace('/[^a-zA-Z0-9_\x7f-\xff]/', '', (string) $value); } /** * Set group name * * @param string $name * @return Zend_Form_DisplayGroup */ public function setName($name) { $name = $this->filtername($name); if (('0' !== $name) && empty($name)) { require_once 'Zend/Form/Exception.php'; throw new Zend_Form_Exception('Invalid name provided; must contain only valid variable characters and be non-empty'); } $this->_name = $name; return $this; } /** * Retrieve group name * * @return string */ public function getName() { return $this->_name; } /** * Set group legend * * @param string $legend * @return Zend_Form_DisplayGroup */ public function setLegend($legend) { return $this->setAttrib('legend', (string) $legend); } /** * Retrieve group legend * * @return string */ public function getLegend() { return $this->getAttrib('legend'); } /** * Set description * * @param string $value * @return Zend_Form_DisplayGroup */ public function setDescription($value) { $this->_description = (string) $value; return $this; } /** * Get description * * @return string */ public function getDescription() { return $this->_description; } /** * Set group order * * @param int $order * @return Zend_Form_Element */ public function setOrder($order) { $this->_order = (int) $order; return $this; } /** * Retrieve group order * * @return int */ public function getOrder() { return $this->_order; } // Elements /** * Add element to stack * * @param Zend_Form_Element $element * @return Zend_Form_DisplayGroup */ public function addElement(Zend_Form_Element $element) { $this->_elements[$element->getName()] = $element; $this->_groupUpdated = true; return $this; } /** * Add multiple elements at once * * @param array $elements * @return Zend_Form_DisplayGroup * @throws Zend_Form_Exception if any element is not a Zend_Form_Element */ public function addElements(array $elements) { foreach ($elements as $element) { if (!$element instanceof Zend_Form_Element) { require_once 'Zend/Form/Exception.php'; throw new Zend_Form_Exception('elements passed via array to addElements() must be Zend_Form_Elements only'); } $this->addElement($element); } return $this; } /** * Set multiple elements at once (overwrites) * * @param array $elements * @return Zend_Form_DisplayGroup */ public function setElements(array $elements) { $this->clearElements(); return $this->addElements($elements); } /** * Retrieve element * * @param string $name * @return Zend_Form_Element|null */ public function getElement($name) { $name = (string) $name; if (isset($this->_elements[$name])) { return $this->_elements[$name]; } return null; } /** * Retrieve elements * @return array */ public function getElements() { return $this->_elements; } /** * Remove a single element * * @param string $name * @return boolean */ public function removeElement($name) { $name = (string) $name; if (array_key_exists($name, $this->_elements)) { unset($this->_elements[$name]); $this->_groupUpdated = true; return true; } return false; } /** * Remove all elements * * @return Zend_Form_DisplayGroup */ public function clearElements() { $this->_elements = array(); $this->_groupUpdated = true; return $this; } // Plugin loader (for decorators) /** * Set plugin loader * * @param Zend_Loader_PluginLoader $loader * @return Zend_Form_DisplayGroup */ public function setPluginLoader(Zend_Loader_PluginLoader $loader) { $this->_loader = $loader; return $this; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -