lithium\template\view\Renderer::_init PHP Method

_init() protected method

The default handlers available are: - url: Allows generating escaped and routed URLs using Router::match(). Note that all falsey values, which includes an empty array, will result in '/' being returned. For empty arrays this behavior is slightly different from using Router::match() directly. - path: Generates an asset path. - options: Converts a set of parameters to HTML attributes into a string. - title: Returns the escaped title. - value: Returns an escaped value. - scripts: Returns a markup string of styles from context. - styles: Returns a markup string of scripts from context. - head
See also: lithium\net\http\Router::match()
See also: lithium\net\http\Media::asset()
See also: lithium\template\Helper::_attributes()
protected _init ( ) : void
return void
    protected function _init()
    {
        parent::_init();
        $req =& $this->_request;
        $ctx =& $this->_context;
        $classes =& $this->_classes;
        $h = $this->_view ? $this->_view->outputFilters['h'] : null;
        $this->_handlers += array('url' => function ($url, $ref, array $options = array()) use(&$classes, &$req, $h) {
            $url = $classes['router']::match($url ?: '', $req, $options);
            return $h ? str_replace('&', '&', $h($url)) : $url;
        }, 'path' => function ($path, $ref, array $options = array()) use(&$classes, &$req, $h) {
            $defaults = array('base' => $req ? $req->env('base') : '');
            $type = 'generic';
            if (is_array($ref) && $ref[0] && $ref[1]) {
                list($helper, $methodRef) = $ref;
                list($class, $method) = explode('::', $methodRef);
                $type = $helper->contentMap[$method];
            }
            $path = $classes['media']::asset($path, $type, $options + $defaults);
            return $h ? $h($path) : $path;
        }, 'options' => '_attributes', 'title' => 'escape', 'value' => 'escape', 'scripts' => function ($scripts) use(&$ctx) {
            return "\n\t" . join("\n\t", $ctx['scripts']) . "\n";
        }, 'styles' => function ($styles) use(&$ctx) {
            return "\n\t" . join("\n\t", $ctx['styles']) . "\n";
        }, 'head' => function ($head) use(&$ctx) {
            return "\n\t" . join("\n\t", $ctx['head']) . "\n";
        });
        unset($this->_config['view']);
    }

Usage Example

Ejemplo n.º 1
0
 /**
  * Initialize the necessary Twig objects & attach them to the current object instance.
  * Attach any configured filters in the lithium app bootstrap to the Twig object.
  *
  * @return void
  */
 protected function _init()
 {
     parent::_init();
     $loader = new Twig_Loader_Filesystem(array());
     $this->environment = new Twig_Environment($loader, $this->_config);
     Twig::$_lithiumContext = $this;
     $library = Libraries::get('li3_twig');
     $defaults = array('register' => array('magicHelperMethod' => false, 'globals' => false), 'extensions' => array());
     $options = empty($library['config']) || !is_array($library['config']) ? $defaults : $library['config'] + $defaults;
     if ($options['register']['magicHelperMethod']) {
         $this->environment->addFunction('*_*', new Twig_Function_Function('li3_twig\\template\\view\\adapter\\Twig::callLithiumHelper'));
     }
     if ($options['register']['globals']) {
         $this->environment->addGlobal('view', $this);
         $this->environment->addGlobal('this', $this);
     }
     if (!empty($options['extensions'])) {
         foreach ($options['extensions'] as $extension) {
             $extensions = $this->helper($extension);
             $this->environment->addExtension($extensions);
         }
     }
 }
All Usage Examples Of lithium\template\view\Renderer::_init