📄 displaygroup.php
字号:
/** * Retrieve plugin loader * * @return Zend_Loader_PluginLoader */ public function getPluginLoader() { return $this->_loader; } /** * Add a prefix path for the plugin loader * * @param string $prefix * @param string $path * @return Zend_Form_DisplayGroup */ public function addPrefixPath($prefix, $path) { $this->getPluginLoader()->addPrefixPath($prefix, $path); return $this; } /** * Add several prefix paths at once * * @param array $spec * @return Zend_Form_DisplayGroup */ public function addPrefixPaths(array $spec) { if (isset($spec['prefix']) && isset($spec['path'])) { return $this->addPrefixPath($spec['prefix'], $spec['path']); } foreach ($spec as $prefix => $paths) { if (is_numeric($prefix) && is_array($paths)) { $prefix = null; if (isset($paths['prefix']) && isset($paths['path'])) { $this->addPrefixPath($paths['prefix'], $paths['path']); } } elseif (!is_numeric($prefix)) { if (is_string($paths)) { $this->addPrefixPath($prefix, $paths); } elseif (is_array($paths)) { foreach ($paths as $path) { $this->addPrefixPath($prefix, $path); } } } } return $this; } // Decorators /** * Set flag to disable loading default decorators * * @param bool $flag * @return Zend_Form_Element */ public function setDisableLoadDefaultDecorators($flag) { $this->_disableLoadDefaultDecorators = (bool) $flag; return $this; } /** * Should we load the default decorators? * * @return bool */ public function loadDefaultDecoratorsIsDisabled() { return $this->_disableLoadDefaultDecorators; } /** * Load default decorators * * @return void */ public function loadDefaultDecorators() { if ($this->loadDefaultDecoratorsIsDisabled()) { return; } $decorators = $this->getDecorators(); if (empty($decorators)) { $this->addDecorator('FormElements') ->addDecorator('HtmlTag', array('tag' => 'dl')) ->addDecorator('Fieldset') ->addDecorator('DtDdWrapper'); } } /** * Instantiate a decorator based on class name or class name fragment * * @param string $name * @param null|array $options * @return Zend_Form_Decorator_Interface */ protected function _getDecorator($name, $options) { $class = $this->getPluginLoader()->load($name); if (null === $options) { $decorator = new $class; } else { $r = new ReflectionClass($class); $decorator = $r->newInstance($options); } return $decorator; } /** * Add a decorator for rendering the group * * @param string|Zend_Form_Decorator_Interface $decorator * @param array|Zend_Config $options Options with which to initialize decorator * @return Zend_Form_DisplayGroup */ public function addDecorator($decorator, $options = null) { if ($decorator instanceof Zend_Form_Decorator_Interface) { $name = get_class($decorator); } elseif (is_string($decorator)) { $decorator = $this->_getDecorator($decorator, $options); $name = get_class($decorator); } elseif (is_array($decorator)) { foreach ($decorator as $name => $spec) { break; } if (is_numeric($name)) { require_once 'Zend/Form/Exception.php'; throw new Zend_Form_Exception('Invalid alias provided to addDecorator; must be alphanumeric string'); } if (is_string($spec)) { $decorator = $this->_getDecorator($spec, $options); } elseif ($spec instanceof Zend_Form_Decorator_Interface) { $decorator = $spec; } } else { require_once 'Zend/Form/Exception.php'; throw new Zend_Form_Exception('Invalid decorator provided to addDecorator; must be string or Zend_Form_Decorator_Interface'); } $this->_decorators[$name] = $decorator; return $this; } /** * Add many decorators at once * * @param array $decorators * @return Zend_Form_DisplayGroup */ public function addDecorators(array $decorators) { foreach ($decorators as $decoratorInfo) { if (is_string($decoratorInfo)) { $this->addDecorator($decoratorInfo); } elseif ($decoratorInfo instanceof Zend_Form_Decorator_Interface) { $this->addDecorator($decoratorInfo); } elseif (is_array($decoratorInfo)) { $argc = count($decoratorInfo); $options = array(); if (isset($decoratorInfo['decorator'])) { $decorator = $decoratorInfo['decorator']; if (isset($decoratorInfo['options'])) { $options = $decoratorInfo['options']; } $this->addDecorator($decorator, $options); } else { switch (true) { case (0 == $argc): break; case (1 <= $argc): $decorator = array_shift($decoratorInfo); case (2 <= $argc): $options = array_shift($decoratorInfo); default: $this->addDecorator($decorator, $options); break; } } } else { require_once 'Zend/Form/Exception.php'; throw new Zend_Form_Exception('Invalid decorator passed to addDecorators()'); } } return $this; } /** * Overwrite all decorators * * @param array $decorators * @return Zend_Form_DisplayGroup */ public function setDecorators(array $decorators) { $this->clearDecorators(); return $this->addDecorators($decorators); } /** * Retrieve a registered decorator * * @param string $name * @return false|Zend_Form_Decorator_Abstract */ public function getDecorator($name) { if (!isset($this->_decorators[$name])) { $decorators = array_keys($this->_decorators); $len = strlen($name); foreach ($decorators as $decorator) { if ($len > strlen($decorator)) { continue; } if (0 === substr_compare($decorator, $name, -$len, $len, true)) { return $this->_decorators[$decorator]; } } return false; } return $this->_decorators[$name]; } /** * Retrieve all decorators * * @return array */ public function getDecorators() { return $this->_decorators; } /** * Remove a single decorator * * @param string $name * @return bool */ public function removeDecorator($name) { $decorator = $this->getDecorator($name); if ($decorator) { $name = get_class($decorator); unset($this->_decorators[$name]); return true; } return false; } /** * Clear all decorators * * @return Zend_Form_DisplayGroup */ public function clearDecorators() { $this->_decorators = array(); return $this; } /** * Set view * * @param Zend_View_Interface $view * @return Zend_Form_DisplayGroup */ public function setView(Zend_View_Interface $view = null) { $this->_view = $view; return $this; } /** * Retrieve view * * @return Zend_View_Interface */ public function getView() { return $this->_view; } /** * Render display group * * @return string */ public function render(Zend_View_Interface $view = null) { if (null !== $view) { $this->setView($view); } $content = ''; foreach ($this->getDecorators() as $decorator) { $decorator->setElement($this); $content = $decorator->render($content); } return $content; } /** * String representation of group * * @return string */ public function __toString() { try { $return = $this->render(); return $return; } catch (Exception $e) { trigger_error($e->getMessage(), E_USER_WARNING); return ''; } } /** * Set translator object * * @param Zend_Translate|Zend_Translate_Adapter|null $translator * @return Zend_Form_DisplayGroup */ public function setTranslator($translator = null) { if ((null === $translator) || ($translator instanceof Zend_Translate_Adapter)) { $this->_translator = $translator; } elseif ($translator instanceof Zend_Translate) { $this->_translator = $translator->getAdapter(); } else { require_once 'Zend/Form/Exception.php'; throw new Zend_Form_Exception('Invalid translator specified'); } return $this; } /** * Retrieve translator object * * @return Zend_Translate_Adapter|null */ public function getTranslator() { if ($this->translatorIsDisabled()) { return null; } if (null === $this->_translator) { require_once 'Zend/Form.php'; return Zend_Form::getDefaultTranslator(); } return $this->_translator; } /** * Indicate whether or not translation should be disabled * * @param bool $flag * @return Zend_Form_DisplayGroup */ public function setDisableTranslator($flag) { $this->_translatorDisabled = (bool) $flag; return $this; } /** * Is translation disabled? * * @return bool */ public function translatorIsDisabled() { return $this->_translatorDisabled; } // Interfaces: Iterator, Countable /** * Current element * * @return Zend_Form_Element */ public function current() { $this->_sort(); current($this->_elementOrder); $key = key($this->_elementOrder); return $this->getElement($key); } /** * Current element * * @return string */ public function key() { $this->_sort(); return key($this->_elementOrder); } /** * Move pointer to next element * * @return void */ public function next() { $this->_sort(); next($this->_elementOrder); } /** * Move pointer to beginning of element loop * * @return void */ public function rewind() { $this->_sort(); reset($this->_elementOrder); } /** * Determine if current element/subform/display group is valid * * @return bool */ public function valid() { $this->_sort(); return (current($this->_elementOrder) !== false); } /** * Count of elements/subforms that are iterable * * @return int */ public function count() { return count($this->_elements); } /** * Sort items according to their order * * @return void */ protected function _sort() { if ($this->_groupUpdated || !is_array($this->_elementOrder)) { $elementOrder = array(); foreach ($this->getElements() as $key => $element) { $elementOrder[$key] = $element->getOrder(); } $items = array(); $index = 0; foreach ($elementOrder as $key => $order) { if (null === $order) { if (array_search($index, $elementOrder, true)) { ++$index; } $items[$index] = $key; ++$index; } else { $items[$order] = $key; } } $items = array_flip($items); asort($items); $this->_elementOrder = $items; $this->_groupUpdated = false; } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -