/** * Set translator * * @param $translator|null \Zend\Translator\Translator * @return \Zend\View\Helper\FormElement */ public function setTranslator($translator = null) { if (null === $translator) { $this->_translator = null; } elseif ($translator instanceof \Zend\Translator\Adapter) { $this->_translator = $translator; } elseif ($translator instanceof \Zend\Translator\Translator) { $this->_translator = $translator->getAdapter(); } else { $e = new \Zend\View\Exception('Invalid translator specified'); $e->setView($this->view); throw $e; } return $this; }
/** * Generates a 'List' element. * * @param array $items Array with the elements of the list * @param boolean $ordered Specifies ordered/unordered list; default unordered * @param array $attribs Attributes for the ol/ul tag. * @return string The list XHTML. */ public function direct(array $items = null, $ordered = false, $attribs = false, $escape = true) { if ($items == null) { throw new \InvalidArgumentException('HTMLList: missing argument. $items is required in htmlList(array $items, $ordered = false, $attribs = false, $escape = true)'); } if (!is_array($items)) { $e = new \Zend\View\Exception('First param must be an array'); $e->setView($this->view); throw $e; } $list = ''; foreach ($items as $item) { if (!is_array($item)) { if ($escape) { $item = $this->view->vars()->escape($item); } $list .= '<li>' . $item . '</li>' . self::EOL; } else { if (6 < strlen($list)) { $list = substr($list, 0, strlen($list) - 6) . $this->direct($item, $ordered, $attribs, $escape) . '</li>' . self::EOL; } else { $list .= '<li>' . $this->direct($item, $ordered, $attribs, $escape) . '</li>' . self::EOL; } } } if ($attribs) { $attribs = $this->_htmlAttribs($attribs); } else { $attribs = ''; } $tag = 'ul'; if ($ordered) { $tag = 'ol'; } return '<' . $tag . $attribs . '>' . self::EOL . $list . '</' . $tag . '>' . self::EOL; }
/** * Returns the helper matching $proxy * * The helper must implement the interface * {@link Zend\View\Helper\Navigation\Helper}. * * @param string $proxy helper name * @param bool $strict [optional] whether * exceptions should be * thrown if something goes * wrong. Default is true. * @return \Zend\View\Helper\Navigation\Helper helper instance * @throws \Zend\Loader\PluginLoader\Exception if $strict is true and * helper cannot be found * @throws \Zend\View\Exception if $strict is true and * helper does not implement * the specified interface */ public function findHelper($proxy, $strict = true) { if (isset($this->_helpers[$proxy])) { return $this->_helpers[$proxy]; } $loader = $this->getPluginLoader(); if ($strict) { $class = $loader->load($proxy); } else { try { $class = $loader->load($proxy); } catch (\Zend\Loader\Exception $e) { return null; } } $helper = new $class(); if (!$helper instanceof AbstractNavigationHelper) { if ($strict) { $e = new \Zend\View\Exception(sprintf( 'Proxy helper "%s" is not an instance of ' . 'Zend\View\Helper\Navigation\Helper', get_class($helper))); $e->setView($this->view); throw $e; } return null; } $helper->setView($this->view); $this->_inject($helper); $this->_helpers[$proxy] = $helper; return $helper; }
/** * Overload * * Proxy to container methods * * @param string $method * @param array $args * @return mixed */ public function __call($method, $args) { $container = $this->getContainer(); if (method_exists($container, $method)) { $return = call_user_func_array(array($container, $method), $args); if ($return === $container) { // If the container is returned, we really want the current object return $this; } return $return; } $e = new \Zend\View\Exception('Method "' . $method . '" does not exist'); $e->setView($this->view); throw $e; }
/** * Set or retrieve doctype * * @param string $doctype * @return \Zend\View\Helper\Doctype */ public function __invoke($doctype = null) { if (null !== $doctype) { switch ($doctype) { case self::XHTML11: case self::XHTML1_STRICT: case self::XHTML1_TRANSITIONAL: case self::XHTML1_FRAMESET: case self::XHTML_BASIC1: case self::XHTML5: case self::HTML4_STRICT: case self::HTML4_LOOSE: case self::HTML4_FRAMESET: case self::HTML5: $this->setDoctype($doctype); break; default: if (substr($doctype, 0, 9) != '<!DOCTYPE') { $e = new \Zend\View\Exception('The specified doctype is malformed'); $e->setView($this->view); throw $e; } if (stristr($doctype, 'xhtml')) { $type = self::CUSTOM_XHTML; } else { $type = self::CUSTOM; } $this->setDoctype($type); $this->_registry['doctypes'][$type] = $doctype; break; } } return $this; }
/** * Returns the helper matching $proxy * * The helper must implement the interface * {@link Zend\View\Helper\Navigation\Helper}. * * @param string $proxy helper name * @param bool $strict [optional] whether * exceptions should be * thrown if something goes * wrong. Default is true. * @return \Zend\View\Helper\Navigation\Helper helper instance * @throws \Zend\Loader\PluginLoader\Exception if $strict is true and * helper cannot be found * @throws \Zend\View\Exception if $strict is true and * helper does not implement * the specified interface */ public function findHelper($proxy, $strict = true) { if (isset($this->_helpers[$proxy])) { return $this->_helpers[$proxy]; } if (!$this->view->getPluginLoader('helper')->getPaths(self::NS)) { $this->view->addHelperPath(str_replace('\\', '/', self::NS), self::NS); } if ($strict) { $helper = $this->view->getHelper($proxy); } else { try { $helper = $this->view->getHelper($proxy); } catch (\Zend\Loader\PluginLoader\Exception $e) { return null; } } if (!$helper instanceof AbstractNavigationHelper) { if ($strict) { $e = new \Zend\View\Exception(sprintf('Proxy helper "%s" is not an instance of ' . 'Zend\\View\\Helper\\Navigation\\Helper', get_class($helper))); $e->setView($this->view); throw $e; } return null; } $this->_inject($helper); $this->_helpers[$proxy] = $helper; return $helper; }