From 0ece1ec4f7f043053798101475ed9f922fb761ca Mon Sep 17 00:00:00 2001 From: Denis Portnov Date: Wed, 4 Jul 2012 22:15:47 +0400 Subject: [PATCH] removal of view helpers - Zend\View\Helper\Translator - Zend\View\Helper\FormElement --- library/Zend/View/Helper/FormElement.php | 194 ---------------------- library/Zend/View/Helper/HtmlList.php | 7 +- library/Zend/View/Helper/Translator.php | 187 --------------------- library/Zend/View/HelperPluginManager.php | 1 - 4 files changed, 2 insertions(+), 387 deletions(-) delete mode 100644 library/Zend/View/Helper/FormElement.php delete mode 100644 library/Zend/View/Helper/Translator.php diff --git a/library/Zend/View/Helper/FormElement.php b/library/Zend/View/Helper/FormElement.php deleted file mode 100644 index 09b545482b2..00000000000 --- a/library/Zend/View/Helper/FormElement.php +++ /dev/null @@ -1,194 +0,0 @@ -_translator; - } - - /** - * Set translator - * - * @param $translator|null \Zend\Translator\Translator - * @return \Zend\View\Helper\FormElement - * @throws Exception\InvalidArgumentException - */ - public function setTranslator($translator = null) - { - if (null === $translator) { - $this->_translator = null; - } elseif ($translator instanceof \Zend\Translator\Adapter\AbstractAdapter) { - $this->_translator = $translator; - } elseif ($translator instanceof \Zend\Translator\Translator) { - $this->_translator = $translator->getAdapter(); - } else { - throw new Exception\InvalidArgumentException('Invalid translator specified'); - } - - return $this; - } - - /** - * Converts parameter arguments to an element info array. - * - * E.g, formExample($name, $value, $attribs, $options, $listsep) is - * the same thing as formExample(array('name' => ...)). - * - * Note that you cannot pass a 'disable' param; you need to pass - * it as an 'attribs' key. - * - * @access protected - * - * @return array An element info array with keys for name, value, - * attribs, options, listsep, disable, and escape. - */ - protected function _getInfo($name, $value = null, $attribs = null, - $options = null, $listsep = null - ) { - // the baseline info. note that $name serves a dual purpose; - // if an array, it's an element info array that will override - // these baseline values. as such, ignore it for the 'name' - // if it's an array. - $info = array( - 'name' => is_array($name) ? '' : $name, - 'id' => is_array($name) ? '' : $name, - 'value' => $value, - 'attribs' => $attribs, - 'options' => $options, - 'listsep' => $listsep, - 'disable' => false, - 'escape' => true, - ); - - // override with named args - if (is_array($name)) { - // only set keys that are already in info - foreach ($info as $key => $val) { - if (isset($name[$key])) { - $info[$key] = $name[$key]; - } - } - - // If all helper options are passed as an array, attribs may have - // been as well - if (null === $attribs) { - $attribs = $info['attribs']; - } - } - - $attribs = (array)$attribs; - - // Normalize readonly tag - if (array_key_exists('readonly', $attribs)) { - $attribs['readonly'] = 'readonly'; - } - - // Disable attribute - if (array_key_exists('disable', $attribs)) { - if (is_scalar($attribs['disable'])) { - // disable the element - $info['disable'] = (bool)$attribs['disable']; - } else if (is_array($attribs['disable'])) { - $info['disable'] = $attribs['disable']; - } - } - - // Set ID for element - if (array_key_exists('id', $attribs)) { - $info['id'] = (string)$attribs['id']; - } else if ('' !== $info['name']) { - $info['id'] = trim(strtr($info['name'], - array('[' => '-', ']' => '')), '-'); - } - - // Determine escaping from attributes - if (array_key_exists('escape', $attribs)) { - $info['escape'] = (bool)$attribs['escape']; - } - - // Determine listsetp from attributes - if (array_key_exists('listsep', $attribs)) { - $info['listsep'] = (string)$attribs['listsep']; - } - - // Remove attribs that might overwrite the other keys. We do this LAST - // because we needed the other attribs values earlier. - foreach ($info as $key => $val) { - if (array_key_exists($key, $attribs)) { - unset($attribs[$key]); - } - } - $info['attribs'] = $attribs; - - // done! - return $info; - } - - /** - * Creates a hidden element. - * - * We have this as a common method because other elements often - * need hidden elements for their operation. - * - * @access protected - * - * @param $name The element name. - * - * @param $value The element value. - * - * @param $attribs Attributes for the element. - * - * @return string A hidden element. - */ - protected function _hidden($name, $value = null, $attribs = null) - { - $escaper = $this->view->plugin('escape'); - return '_htmlAttribs($attribs) . $this->getClosingBracket(); - } -} diff --git a/library/Zend/View/Helper/HtmlList.php b/library/Zend/View/Helper/HtmlList.php index 8a42ffc0da8..7c0556a8623 100644 --- a/library/Zend/View/Helper/HtmlList.php +++ b/library/Zend/View/Helper/HtmlList.php @@ -30,7 +30,7 @@ * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ -class HtmlList extends FormElement +class HtmlList extends AbstractHtmlElement { /** * Generates a 'List' element. @@ -68,10 +68,7 @@ public function __invoke(array $items, $ordered = false, $attribs = false, $esca $attribs = ''; } - $tag = 'ul'; - if ($ordered) { - $tag = 'ol'; - } + $tag = ($ordered) ? 'ol' : 'ul'; return '<' . $tag . $attribs . '>' . self::EOL . $list . '' . self::EOL; } diff --git a/library/Zend/View/Helper/Translator.php b/library/Zend/View/Helper/Translator.php deleted file mode 100644 index e82420240be..00000000000 --- a/library/Zend/View/Helper/Translator.php +++ /dev/null @@ -1,187 +0,0 @@ -setTranslator($translate); - } - } - - /** - * Mock __invoke for manual call - * - * @see __invoke - * @param string $messageid Id of the message to be translated - * @return string|\Zend\View\Helper\Translator Translated message - */ - public function translate($messageid = null) - { - $options = func_get_args(); - return call_user_func_array(array($this, '__invoke'), $options); - } - - /** - * Translate a message - * You can give multiple params or an array of params. - * If you want to output another locale just set it as last single parameter - * Example 1: translate('%1\$s + %2\$s', $value1, $value2, $locale); - * Example 2: translate('%1\$s + %2\$s', array($value1, $value2), $locale); - * - * @param string $messageid Id of the message to be translated - * @return string|\Zend\View\Helper\Translator Translated message - */ - public function __invoke($messageid = null) - { - if ($messageid === null) { - return $this; - } - - $translator = $this->getTranslator(); - $options = func_get_args(); - - array_shift($options); - $count = count($options); - $locale = null; - if ($count > 0) { - if (Locale::isLocale($options[($count - 1)]) !== false) { - // Don't treat last option as the locale if doing so will result in an error - if (is_array($options[0]) || @vsprintf($messageid, array_slice($options, 0, -1)) !== false) { - $locale = array_pop($options); - } - } - } - - if ((count($options) === 1) and (is_array($options[0]) === true)) { - $options = $options[0]; - } - - if ($translator !== null) { - $messageid = $translator->translate($messageid, $locale); - } - - if (count($options) === 0) { - return $messageid; - } - - return vsprintf($messageid, $options); - } - - /** - * Sets a translation Adapter for translation - * - * @param Translation|TranslationAdapter $translator - * @return Translator - * @throws Exception\InvalidArgumentException When no or a false instance was set - */ - public function setTranslator($translator) - { - if ($translator instanceof TranslationAdapter) { - $this->translator = $translator; - } else if ($translator instanceof Translation) { - $this->translator = $translator->getAdapter(); - } else { - throw new Exception\InvalidArgumentException( - 'You must set an instance of Zend\Translator\Translator or Zend\Translator\Adapter' - ); - } - - return $this; - } - - /** - * Retrieve translation object - * - * @return TranslationAdapter|null - */ - public function getTranslator() - { - return $this->translator; - } - - /** - * Set's a new locale for all further translations - * - * @param string|Locale $locale New locale to set - * @return Translator - * @throws Exception\RuntimeException When no Translation instance was set - */ - public function setLocale($locale = null) - { - $translator = $this->getTranslator(); - if ($translator === null) { - throw new Exception\RuntimeException( - 'You must set an instance of Zend\Translator\Translator or Zend\Translator\Adapter' - ); - } - - $translator->setLocale($locale); - return $this; - } - - /** - * Returns the set locale for translations - * - * @return string|Locale - * @throws Exception\RuntimeException When no Translation instance was set - */ - public function getLocale() - { - $translator = $this->getTranslator(); - if ($translator === null) { - throw new Exception\RuntimeException( - 'You must set an instance of Zend\Translator\Translator or Zend\Translator\Adapter' - ); - } - - return $translator->getLocale(); - } -} diff --git a/library/Zend/View/HelperPluginManager.php b/library/Zend/View/HelperPluginManager.php index 28eb3015aa8..5d649900eb1 100644 --- a/library/Zend/View/HelperPluginManager.php +++ b/library/Zend/View/HelperPluginManager.php @@ -74,7 +74,6 @@ class HelperPluginManager extends AbstractPluginManager 'renderchildmodel' => 'Zend\View\Helper\RenderChildModel', 'rendertoplaceholder' => 'Zend\View\Helper\RenderToPlaceholder', 'serverurl' => 'Zend\View\Helper\ServerUrl', - 'translator' => 'Zend\View\Helper\Translator', 'viewmodel' => 'Zend\View\Helper\ViewModel', );