예제 #1
0
 /**
  * @param null $path
  * @param null $prefix
  * @param array $options
  */
 public function initView($path = null, $prefix = null, array $options = array())
 {
     if (null === $this->view) {
         $view = new View();
         $view->setRequest($this->getRequest());
         $view->addHelperPath(PIMCORE_PATH . "/lib/Pimcore/View/Helper", "\\Pimcore\\View\\Helper\\");
         $this->setView($view);
     }
     parent::initView($path, $prefix, $options);
     $this->setViewSuffix(View::getViewScriptSuffix());
     // this is very important, the initView could be called multiple times.
     // if we add the path on every call, we have big performance issues.
     if ($this->isInitialized) {
         return;
     }
     $this->isInitialized = true;
     $paths = $this->view->getScriptPaths();
     // script pathes for layout path
     foreach (array_reverse($paths) as $path) {
         $path = str_replace("\\", "/", $path);
         if (!in_array($path, $paths)) {
             $this->view->addScriptPath($path);
         }
         $path = str_replace("/scripts", "/layouts", $path);
         if (!in_array($path, $paths)) {
             $this->view->addScriptPath($path);
         }
     }
 }
예제 #2
0
 public function testInitViewWithOptions()
 {
     $this->request->setModuleName('foo')->setControllerName('index');
     $controller = new Foo_IndexController($this->request, $this->response, array());
     $this->helper->setActionController($controller);
     $viewDir = dirname(__FILE__) . str_repeat(DIRECTORY_SEPARATOR . '..', 2) . DIRECTORY_SEPARATOR . 'views';
     $this->helper->initView($viewDir, 'Baz_Bat', array('neverRender' => true, 'noRender' => true, 'noController' => true, 'viewSuffix' => 'php', 'scriptAction' => 'foo', 'responseSegment' => 'baz'));
     $this->assertTrue($this->helper->getNeverRender());
     $this->assertTrue($this->helper->getNoRender());
     $this->assertTrue($this->helper->getNoController());
     $this->assertEquals('php', $this->helper->getViewSuffix());
     $this->assertEquals('foo', $this->helper->getScriptAction());
     $this->assertEquals('baz', $this->helper->getResponseSegment());
     $scriptPaths = $this->helper->view->getScriptPaths();
     $scriptPath = $scriptPaths[0];
     $this->assertContains($viewDir, $scriptPath);
     $helperPaths = $this->helper->view->getHelperPaths();
     $found = false;
     foreach ($helperPaths as $path) {
         if ('Baz_Bat_Helper_' == $path['prefix']) {
             $found = true;
         }
     }
     $this->assertTrue($found, 'Helper prefix not set according to spec: ' . var_export($helperPaths, 1));
     $filterPaths = $this->helper->view->getFilterPaths();
     $found = false;
     foreach ($filterPaths as $path) {
         if ('Baz_Bat_Filter_' == $path['prefix']) {
             $found = true;
         }
     }
     $this->assertTrue($found, 'Filter prefix not set according to spec' . var_export($filterPaths, 1));
 }
 /**
  * @see ZF-2443
  */
 public function testStockInflectorWorksWithViewBaseSpec()
 {
     $this->request->setModuleName('bar')->setControllerName('index')->setActionName('admin');
     $controller = new Bar_IndexController($this->request, $this->response, array());
     $this->helper->setActionController($controller);
     $this->helper->setViewBasePathSpec(':moduleDir/:module');
     $this->helper->initView();
     $viewScriptPaths = $this->helper->view->getAllPaths();
     $expectedPathRegex = '#modules/bar/bar/scripts/$#';
     $this->assertRegExp($expectedPathRegex, $this->_normalizePath($viewScriptPaths['script'][0]));
     $this->assertEquals($this->helper->getViewScript(), 'index/admin.phtml');
 }
예제 #4
0
 /**
  * @see ZF-2443
  */
 public function testStockInflectorWorksWithViewBaseSpec()
 {
     $this->request->setModuleName('bar')->setControllerName('index')->setActionName('admin');
     $controller = new Bar_IndexController($this->request, $this->response, array());
     $this->helper->setActionController($controller);
     $this->helper->setViewBasePathSpec(':moduleDir/:module');
     $this->helper->initView();
     $viewScriptPaths = $this->helper->view->getAllPaths();
     // we need this until View decides to not use DIRECTORY_SEPARATOR
     $expectedPathRegex = DIRECTORY_SEPARATOR == '\\' ? '#modules\\\\bar\\\\bar\\\\scripts\\\\$#' : '#modules/bar/bar/scripts/$#';
     $this->assertRegExp($expectedPathRegex, $viewScriptPaths['script'][0]);
     $this->assertEquals($this->helper->getViewScript(), 'index/admin.phtml');
 }
예제 #5
0
 /**
  * @param null $path
  * @param null $prefix
  * @param array $options
  */
 public function initView($path = null, $prefix = null, array $options = array())
 {
     if (null === $this->view) {
         $view = new Pimcore_View();
         $view->setRequest($this->getRequest());
         $view->addHelperPath(PIMCORE_PATH . "/lib/Pimcore/View/Helper", "Pimcore_View_Helper_");
         $this->setView($view);
     }
     parent::initView($path, $prefix, $options);
     // script pathes for layout path
     foreach (array_reverse($this->view->getScriptPaths()) as $path) {
         $path = str_replace("\\", "/", $path);
         $this->view->addScriptPath($path);
         $this->view->addScriptPath(str_replace("/scripts", "/layouts", $path));
     }
     $this->setViewSuffix(Pimcore_View::getViewScriptSuffix());
 }
예제 #6
0
    /**
     * @issue ZF-2443
     */
    public function testStockInflectorWorksWithViewBaseSpec()
    {
        $this->request->setModuleName('bar')  // bar must exist so the ViewRendere doesnt throw an exception
                      ->setControllerName('index')
                      ->setActionName('admin');
        $controller = new Bar_IndexController($this->request, $this->response, array());
        $this->helper->setActionController($controller);
                      
        $this->helper->setView($view = new Zend_View());
        $this->helper->setViewBasePathSpec(':moduleDir/:module');
        $this->helper->initView();
        
        $viewScriptPaths = $view->getAllPaths(); 

        $this->assertRegExp('#modules/bar/bar/scripts/$#', $viewScriptPaths['script'][0]);
        $this->assertEquals($this->helper->getViewScript(), 'index/admin.phtml');
    }
예제 #7
0
    /**
     * @group ZF-2443
     */
    public function testStockInflectorWorksWithViewBaseSpec()
    {
        $this->request->setModuleName('bar')  // bar must exist so the ViewRendere doesnt throw an exception
                      ->setControllerName('index')
                      ->setActionName('admin');
        $controller = new \Bar\IndexController($this->request, $this->response, array());
        $controller->setHelperBroker($this->broker);
        $this->helper->setActionController($controller);

        $this->helper->setViewBasePathSpec(':moduleDir/:module');
        $this->helper->initView();

        $viewScriptPaths = $this->helper->view->resolver()->getPaths();

        $expectedPathRegex = '#modules/bar/bar/scripts/$#';
        $this->assertRegExp(
            $expectedPathRegex,
            $this->_normalizePath($viewScriptPaths[0])
            );
        $this->assertEquals($this->helper->getViewScript(), 'index/admin.phtml');
    }
예제 #8
0
 /**
  * Initialize the view object
  *
  * $options may contain the following keys:
  * - neverRender - flag dis/enabling postDispatch() autorender (affects all subsequent calls)
  * - noController - flag indicating whether or not to look for view scripts in subdirectories named after the controller
  * - noRender - flag indicating whether or not to autorender postDispatch()
  * - responseSegment - which named response segment to render a view script to
  * - scriptAction - what action script to render
  * - viewBasePathSpec - specification to use for determining view base path
  * - viewScriptPathSpec - specification to use for determining view script paths
  * - viewScriptPathNoControllerSpec - specification to use for determining view script paths when noController flag is set
  * - viewSuffix - what view script filename suffix to use
  *
  * @param  string $path
  * @param  string $prefix
  * @param  array  $options
  * @throws Zend_Controller_Action_Exception
  * @return void
  */
 public function initView($path = null, $prefix = null, array $options = array())
 {
     $this->setView($this->getServiceLocator()->get('View'));
     parent::initView($path, $prefix, $options);
 }