Exemplo n.º 1
0
 /**
  * Retrieve a value and return $default if there is no element set.
  *
  * @param  string $name
  * @param  mixed  $default
  * @return mixed
  */
 public function get($name, $default = null)
 {
     $name = $this->inflector->filter(['name' => $name]);
     if (array_key_exists($name, $this->data)) {
         return $this->data[$name];
     }
     return $default;
 }
Exemplo n.º 2
0
    /**
     * Render layout
     *
     * Sets internal script path as last path on script path stack, assigns
     * layout variables to view, determines layout name using inflector, and
     * renders layout view script.
     *
     * $name will be passed to the inflector as the key 'script'.
     *
     * @param  mixed $name
     * @return mixed
     */
    public function render($name = null)
    {
        if (null === $name) {
            $name = $this->getLayout();
        }

        if ($this->inflectorEnabled() && (null !== ($inflector = $this->getInflector())))
        {
            $name = $this->_inflector->filter(array('script' => $name));
        }

        $view = $this->getView();

        if (null !== ($path = $this->getViewScriptPath())) {
            if ($view instanceof \Zend\View\PhpRenderer) {
                $view->resolver()->addPath($path);
            }
        } elseif (null !== ($path = $this->getViewBasePath())) {
            if ($view instanceof \Zend\View\PhpRenderer) {
                $view->resolver()->addPath($path . '/scripts');
            }
        }

        return $view->render($name);
    }
Exemplo n.º 3
0
 /**
  * Set inflector
  *
  * @param  \Zend\Filter\Inflector $inflector
  * @param  boolean               $reference Whether the moduleDir, target, and suffix should be set as references to ViewRenderer properties
  * @return \Zend\Controller\Action\Helper\ViewRenderer Provides a fluent interface
  */
 public function setInflector(Filter\Inflector $inflector, $reference = false)
 {
     $this->_inflector = $inflector;
     if ($reference) {
         $this->_inflector->setStaticRuleReference('suffix', $this->_viewSuffix)->setStaticRuleReference('moduleDir', $this->_moduleDir)->setTargetReference($this->_inflectorTarget);
     }
     return $this;
 }
Exemplo n.º 4
0
 /**
  * Render layout
  *
  * Sets internal script path as last path on script path stack, assigns
  * layout variables to view, determines layout name using inflector, and
  * renders layout view script.
  *
  * $name will be passed to the inflector as the key 'script'.
  *
  * @param  mixed $name
  * @return mixed
  */
 public function render($name = null)
 {
     if (null === $name) {
         $name = $this->getLayout();
     }
     if ($this->inflectorEnabled() && null !== ($inflector = $this->getInflector())) {
         $name = $this->_inflector->filter(array('script' => $name));
     }
     $view = $this->getView();
     if (null !== ($path = $this->getViewScriptPath())) {
         if (method_exists($view, 'addScriptPath')) {
             $view->addScriptPath($path);
         } else {
             $view->setScriptPath($path);
         }
     } elseif (null !== ($path = $this->getViewBasePath())) {
         $view->addBasePath($path, $this->_viewBasePrefix);
     }
     return $view->render($name);
 }
Exemplo n.º 5
0
    public function testCustomInflectorUsesViewRendererTargetWhenPassedInWithReferenceFlag()
    {
        $this->request->setModuleName('bar')
                      ->setControllerName('index')
                      ->setActionName('test');
        $controller = new \Bar\IndexController($this->request, $this->response, array());
        $controller->setHelperBroker($this->broker);

        $this->helper->view->resolver()->addPath($this->basePath . '/_files/modules/bar/views');


        $inflector = new Filter\Inflector('test.phtml');
        $inflector->addRules(array(
            ':module'     => array('Word\CamelCaseToDash', 'stringToLower'),
            ':controller' => array('Word\CamelCaseToDash', new \Zend\Filter\Word\UnderscoreToSeparator(DIRECTORY_SEPARATOR), 'StringToLower'),
            ':action'     => array(
                'Word\CamelCaseToDash',
                new Filter\PregReplace('/[^a-z0-9]+/i', '-'),
                'StringToLower'
            ),
        ));
        $this->helper->setInflector($inflector, true);

        $this->helper->render();
        $body = $this->response->getBody();
        $this->assertContains('Rendered index/test.phtml in bar module', $body);
    }
Exemplo n.º 6
0
 /**
  * Returns template name
  *
  * If a template name is not specified as a widget's param
  * it is auto created from widget type name
  * (Note: each word of the widget type name will be separated with a dash ('-').
  *
  * @return string
  */
 protected function prepareTplName()
 {
     // We're separating each word of a widget class name using a dash (‘-‘).
     $inflector = new Inflector(':tplName');
     $inflector->setRules(array(':tplName' => array('Word\\CamelCaseToDash')));
     $className = $this->getWidgetTypeName();
     $tplName = $inflector->filter(array('tplName' => $className));
     return $tplName;
 }
Exemplo n.º 7
0
 /**
  * @group ZF-8997
  */
 public function testPassingZendConfigObjectToSetConfigSetsStateAndRules()
 {
     $config = $this->getConfig();
     $inflector = new InflectorFilter();
     $inflector->setOptions($config);
     $this->_testOptions($inflector);
 }