multi.php

来自「Bug tracker, and reporter.」· PHP 代码 · 共 228 行

PHP
228
字号
<?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 * @subpackage Element * @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_Element_Xhtml */require_once 'Zend/Form/Element/Xhtml.php';/** * Base class for multi-option form elements *  * @category   Zend * @package    Zend_Form * @subpackage Element * @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: Multi.php 8971 2008-03-21 18:31:07Z matthew $ */abstract class Zend_Form_Element_Multi extends Zend_Form_Element_Xhtml{    /**     * Array of options for multi-item     * @var array     */    public $options = array();    /**     * Separator to use between options; defaults to '<br />'.     * @var string     */    protected $_separator = '<br />';    /**     * Which values are translated already?     * @var array     */    protected $_translated = array();    /**     * Retrieve separator     *     * @return mixed     */    public function getSeparator()    {        return $this->_separator;    }    /**     * Set separator     *     * @param mixed $separator     * @return self     */    public function setSeparator($separator)    {        $this->_separator = $separator;        return $this;    }    /**     * Retrieve options array     *      * @return array     */    protected function _getMultiOptions()    {        if (null === $this->options || !is_array($this->options)) {            $this->options = array();        }        return $this->options;    }    /**     * Add an option     *      * @param  string $option      * @param  string $value     * @return Zend_Form_Element_Multi     */    public function addMultiOption($option, $value = '')    {        $option  = (string) $option;        $this->_getMultiOptions();        if (!$this->_translateOption($option, $value)) {            $this->options[$option] = $value;        }        return $this;    }    /**     * Add many options at once     *      * @param  array $options      * @return Zend_Form_Element_Multi     */    public function addMultiOptions(array $options)    {        foreach ($options as $option => $value) {            if (is_array($value)                 && array_key_exists('key', $value)                && array_key_exists('value', $value)            ) {                $this->addMultiOption($value['key'], $value['value']);            } else {                $this->addMultiOption($option, $value);            }        }        return $this;    }    /**     * Set all options at once (overwrites)     *     * @param  array $options     * @return Zend_Form_Element_Multi     */    public function setMultiOptions(array $options)    {        $this->clearMultiOptions();        return $this->addMultiOptions($options);    }    /**     * Retrieve single multi option     *      * @param  string $option      * @return mixed     */    public function getMultiOption($option)    {        $option  = (string) $option;        $this->_getMultiOptions();        if (isset($this->options[$option])) {            $this->_translateOption($option, $this->options[$option]);            return $this->options[$option];        }        return null;    }    /**     * Retrieve options     *     * @return array     */    public function getMultiOptions()    {        $this->_getMultiOptions();        foreach ($this->options as $option => $value) {            $this->_translateOption($option, $value);        }        return $this->options;    }    /**     * Remove a single multi option     *      * @param  string $option      * @return bool     */    public function removeMultiOption($option)    {        $option  = (string) $option;        $this->_getMultiOptions();        if (isset($this->options[$option])) {            unset($this->options[$option]);            if (isset($this->_translated[$option])) {                unset($this->_translated[$option]);            }            return true;        }        return false;    }    /**     * Clear all options     *      * @return Zend_Form_Element_Multi     */    public function clearMultiOptions()    {        $this->options = array();        $this->_translated = array();        return $this;    }    /**     * Translate an option     *      * @param  string $option      * @param  string $value     * @return bool     */    protected function _translateOption($option, $value)    {        if (!isset($this->_translated[$option])             && (null !== ($translator = $this->getTranslator()))            && $translator->isTranslated($value))         {            $this->options[$option] = $translator->translate($value);            $this->_translated[$option] = true;            return true;        }         return false;    }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?