/** * Create and return the view helper manager * * @param ServiceLocatorInterface $serviceLocator * @return ViewHelperInterface * @throws Exception\RuntimeException */ public function createService(ServiceLocatorInterface $serviceLocator) { $plugins = parent::createService($serviceLocator); foreach ($this->defaultHelperMapClasses as $configClass) { if (is_string($configClass) && class_exists($configClass)) { $config = new $configClass(); if (!$config instanceof ConfigInterface) { throw new Exception\RuntimeException(sprintf('Invalid service manager configuration class provided; received "%s", expected class implementing %s', $configClass, 'Zend\\ServiceManager\\ConfigInterface')); } $config->configureServiceManager($plugins); } } // Configure URL view helper with router $plugins->setFactory('url', function () use($serviceLocator) { $helper = new ViewHelper\Url(); $router = Console::isConsole() ? 'HttpRouter' : 'Router'; $helper->setRouter($serviceLocator->get($router)); $match = $serviceLocator->get('application')->getMvcEvent()->getRouteMatch(); if ($match instanceof RouteMatch) { $helper->setRouteMatch($match); } return $helper; }); $plugins->setFactory('basepath', function () use($serviceLocator) { $config = $serviceLocator->has('Config') ? $serviceLocator->get('Config') : array(); $basePathHelper = new ViewHelper\BasePath(); if (Console::isConsole() && isset($config['view_manager']) && isset($config['view_manager']['base_path_console'])) { $basePathHelper->setBasePath($config['view_manager']['base_path_console']); return $basePathHelper; } if (isset($config['view_manager']) && isset($config['view_manager']['base_path'])) { $basePathHelper->setBasePath($config['view_manager']['base_path']); return $basePathHelper; } $request = $serviceLocator->get('Request'); if (is_callable(array($request, 'getBasePath'))) { $basePathHelper->setBasePath($request->getBasePath()); } return $basePathHelper; }); /** * Configure doctype view helper with doctype from configuration, if available. * * Other view helpers depend on this to decide which spec to generate their tags * based on. This is why it must be set early instead of later in the layout phtml. */ $plugins->setFactory('doctype', function () use($serviceLocator) { $config = $serviceLocator->has('Config') ? $serviceLocator->get('Config') : array(); $config = isset($config['view_manager']) ? $config['view_manager'] : array(); $doctypeHelper = new ViewHelper\Doctype(); if (isset($config['doctype']) && $config['doctype']) { $doctypeHelper->setDoctype($config['doctype']); } return $doctypeHelper; }); return $plugins; }
/** * Constructor * * @param \Zend\View\Helper\EscapeHtmlAttr $escapeHtmlAttr EscapeHtmlAttr helper * @param \Zend\View\Helper\Doctype $doctype Doctype helper */ public function __construct(\Zend\View\Helper\EscapeHtmlAttr $escapeHtmlAttr, \Zend\View\Helper\Doctype $doctype) { $this->_escapeHtmlAttr = $escapeHtmlAttr; if (!$doctype->isXhtml()) { $this->_emptyTags = array('area', 'base', 'br', 'col', 'hr', 'img', 'input', 'link', 'meta', 'param'); if ($doctype->isHtml5()) { $this->_emptyTags = array_merge($this->_emptyTags, array('command', 'keygen', 'source')); } } }
public function testStringificationReturnsDoctypeString() { $doctype = $this->helper->__invoke(Helper\Doctype::XHTML1_STRICT); $string = $doctype->__toString(); $registry = \Zend\Registry::get('Zend_View_Helper_Doctype'); $this->assertEquals($registry['doctypes'][Helper\Doctype::XHTML1_STRICT], $string); }
/** * Sets up the fixture, for example, open a network connection. * This method is called before a test is executed. * * @return void */ public function setUp() { Helper\Doctype::unsetDoctypeRegistry(); $this->basePath = __DIR__ . '/_files/modules'; $this->view = new View(); $this->helper = new Helper\HeadLink(); $this->helper->setView($this->view); }
public function setUp() { Doctype::unsetDoctypeRegistry(); $this->renderer = new PhpRenderer(); $helpers = $this->renderer->getHelperPluginManager(); $config = new HelperConfig(); $config->configureServiceManager($helpers); $this->helper->setView($this->renderer); }
public function testIsRdfaReturnsTrueForRdfaDoctype() { $this->assertFalse($this->helper->isRdfa()); $doctypes = array(Helper\Doctype::XHTML11, Helper\Doctype::XHTML1_STRICT, Helper\Doctype::XHTML1_TRANSITIONAL, Helper\Doctype::XHTML1_FRAMESET, Helper\Doctype::XHTML_BASIC1, Helper\Doctype::XHTML5, Helper\Doctype::HTML4_STRICT, Helper\Doctype::HTML4_LOOSE, Helper\Doctype::HTML4_FRAMESET, Helper\Doctype::HTML5); foreach ($doctypes as $type) { $this->assertFalse($this->helper->__invoke($type)->isRdfa()); } $this->assertTrue($this->helper->__invoke(Helper\Doctype::XHTML1_RDFA1)->isRdfa()); }
/** * Sets up the fixture, for example, open a network connection. * This method is called before a test is executed. * * @return void */ public function setUp() { $this->error = false; Helper\Doctype::unsetDoctypeRegistry(); $this->basePath = __DIR__ . '/_files/modules'; $this->view = new View(); $this->view->plugin('doctype')->__invoke('XHTML1_STRICT'); $this->helper = new Helper\HeadMeta(); $this->helper->setView($this->view); }
public function testStringificationReturnsDoctypeString() { $doctype = $this->helper->__invoke(Helper\Doctype::XHTML1_STRICT); $string = $doctype->__toString(); $this->assertEquals('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">', $string); }
/** * Create and return a Doctype helper factory. * * Other view helpers depend on this to decide which spec to generate their tags * based on. This is why it must be set early instead of later in the layout phtml. * * @param ContainerInterface $services * @return callable */ private function createDoctypeHelperFactory(ContainerInterface $services) { return function () use($services) { $config = $services->has('config') ? $services->get('config') : []; $config = isset($config['view_manager']) ? $config['view_manager'] : []; $helper = new ViewHelper\Doctype(); if (isset($config['doctype']) && $config['doctype']) { $helper->setDoctype($config['doctype']); } return $helper; }; }
/** * Create and return the view helper manager * * @param ServiceLocatorInterface $serviceLocator * @return ViewHelperInterface * @throws Exception\RuntimeException */ public function createService(ServiceLocatorInterface $serviceLocator) { $pluginManagerClass = static::PLUGIN_MANAGER_CLASS; $plugins = new $pluginManagerClass(); $plugins->setServiceLocator($serviceLocator); $configuration = $serviceLocator->get('Config'); if (isset($configuration['di']) && $serviceLocator->has('Di')) { $di = $serviceLocator->get('Di'); $plugins->addAbstractFactory(new DiAbstractServiceFactory($di, DiAbstractServiceFactory::USE_SL_BEFORE_DI)); } foreach ($this->defaultHelperMapClasses as $configClass) { if (is_string($configClass) && class_exists($configClass)) { $config = new $configClass(); } if (!$config instanceof ConfigInterface) { throw new Exception\RuntimeException(sprintf('Invalid service manager configuration class provided; received "%s", expected class implementing %s', $configClass, 'Zend\\ServiceManager\\ConfigInterface')); } $config->configureServiceManager($plugins); } // Configure URL view helper with router $plugins->setFactory('url', function ($sm) use($serviceLocator) { $helper = new ViewHelper\Url(); $helper->setRouter($serviceLocator->get('Router')); $match = $serviceLocator->get('application')->getMvcEvent()->getRouteMatch(); if ($match instanceof RouteMatch) { $helper->setRouteMatch($match); } return $helper; }); $plugins->setFactory('basepath', function ($sm) use($serviceLocator) { $config = $serviceLocator->get('Config'); $config = $config['view_manager']; $basePathHelper = new ViewHelper\BasePath(); if (isset($config['base_path'])) { $basePath = $config['base_path']; } else { $basePath = $serviceLocator->get('Request')->getBasePath(); } $basePathHelper->setBasePath($basePath); return $basePathHelper; }); /** * Configure doctype view helper with doctype from configuration, if available. * * Other view helpers depend on this to decide which spec to generate their tags * based on. This is why it must be set early instead of later in the layout phtml. */ $plugins->setFactory('doctype', function ($sm) use($serviceLocator) { $config = $serviceLocator->get('Config'); $config = $config['view_manager']; $doctypeHelper = new ViewHelper\Doctype(); if (isset($config['doctype'])) { $doctypeHelper->setDoctype($config['doctype']); } return $doctypeHelper; }); return $plugins; }