コード例 #1
0
 /**
  * Create a new view renderer
  *
  * @return \Zend\View\Renderer\PhpRenderer
  */
 protected function _createView()
 {
     $application = \Library\Application::init('Console', true);
     $view = new \Zend\View\Renderer\PhpRenderer();
     $view->setHelperPluginManager($application->getServiceManager()->get('ViewHelperManager'));
     return $view;
 }
コード例 #2
0
 /**
  * Create a new view renderer
  *
  * @return \Zend\View\Renderer\PhpRenderer
  */
 protected function _createView()
 {
     // Clone helper plugin manager to prevent state changes leaking into other tests
     $plugins = clone \Library\Application::getService('ViewHelperManager');
     $view = new \Zend\View\Renderer\PhpRenderer();
     $view->setHelperPluginManager($plugins);
     return $view;
 }
コード例 #3
0
    public function testFormElementHelperIntegration()
    {
        $element = new \Zend\Form\Element\Select('test');
        $element->setAttribute('type', 'select_untranslated')->setValueOptions(array('Yes<b>', 'No'));
        $expected = <<<EOT
<select name="test"><option value="0">Yes&lt;b&gt;</option>
<option value="1">No</option></select>
EOT;
        $view = new \Zend\View\Renderer\PhpRenderer();
        $view->setHelperPluginManager(static::$_helperManager);
        $helper = static::$_helperManager->get('formElement');
        $helper->setView($view);
        $this->assertEquals($expected, $helper($element));
    }
コード例 #4
0
    public function testFormElementHelperIntegration()
    {
        $element = new \Library\Form\Element\SelectSimple('test');
        $element->setValueOptions(array('option<b>1', 'option2'))->setValue('option<b>1');
        $expected = <<<EOT
<select name="test">
<option selected="selected">option&lt;b&gt;1</option>
<option>option2</option>
</select>
EOT;
        $view = new \Zend\View\Renderer\PhpRenderer();
        $view->setHelperPluginManager(static::$_helperManager);
        $helper = static::$_helperManager->get('formElement');
        $helper->setView($view);
        $this->assertEquals($expected, $helper($element));
    }
コード例 #5
0
 /**
  * Register service manager & set up Twig if
  * we have an environment
  *
  * @param \Pimple\Container $container
  */
 public function register(\Pimple\Container $container)
 {
     $smConfigurator = new ServiceManagerConfigurator();
     $serviceManager = $smConfigurator->createServiceManager($this->settings);
     $container['serviceManager'] = $serviceManager;
     if ($container['view'] instanceof \Slim\Views\Twig) {
         // Register Zend\Forms view helpers
         $viewHelperManager = $serviceManager->get('ViewHelperManager');
         $renderer = new \Zend\View\Renderer\PhpRenderer();
         $renderer->setHelperPluginManager($viewHelperManager);
         $environment = $container['view']->getEnvironment();
         $environment->registerUndefinedFunctionCallback(function ($name) use($viewHelperManager, $renderer) {
             if (!$viewHelperManager->has($name)) {
                 return false;
             }
             $callable = [$renderer->plugin($name), '__invoke'];
             $options = ['is_safe' => ['html']];
             return new \Twig_SimpleFunction(null, $callable, $options);
         });
     }
 }
コード例 #6
0
 /**
  * Create a view renderer
  *
  * A new view renderer instance is created on every call. If the state of
  * the renderer or a helper needs to be preserved, call this only once and
  * store it in a variable.
  *
  * @return \Zend\View\Renderer\PhpRenderer
  */
 protected function _createView()
 {
     // Clone helper plugin manager to get the helpers in a fresh state.
     // This is important for helpers like HeadScript that store information
     // across invocations. These state changes must not leak into other
     // tests.
     $plugins = clone \Library\Application::getService('ViewHelperManager');
     $view = new \Zend\View\Renderer\PhpRenderer();
     $view->setHelperPluginManager($plugins);
     return $view;
 }