Exemple #1
0
 protected function _render($method, $string, $params, array $options = array())
 {
     foreach ($params as $key => $value) {
         $params[$key] = $this->_context->applyHandler($this, $method, $key, $value, $options);
     }
     $strings = $this->_context ? $this->_context->strings() : $this->_strings;
     return String::insert(isset($strings[$string]) ? $strings[$string] : $string, $params);
 }
 /**
  * Render a string template after applying context filters
  * Use examples in the Html::link() method:
  * `return $this->_render(__METHOD__, 'link', compact('title', 'url', 'options'), $scope);`
  *
  * @param string $method name of method that is calling the render (for context filters)
  * @param string $string template key (in Helper::_strings) to render
  * @param array $params associated array of template inserts {:key} will be replaced by value
  * @param array $options Available options:
  *              - `'handlers'` _array_: Before inserting `$params` inside the string template,
  *              `$this->_context`'s handlers are applied to each value of `$params` according
  *              to the key (e.g `$params['url']`, which is processed by the `'url'` handler
  *              via `$this->_context->applyHandler()`).
  *              The `'handlers'` option allow to set custom mapping beetween `$params`'s key and
  *              `$this->_context`'s handlers. e.g. the following handler:
  *              `'handlers' => array('url' => 'path')` will make `$params['url']` to be
  *              processed by the `'path'` handler instead of the `'url'` one.
  * @return string Rendered HTML
  */
 protected function _render($method, $string, $params, array $options = array())
 {
     $strings = $this->_strings;
     if ($this->_context) {
         foreach ($params as $key => $value) {
             $handler = isset($options['handlers'][$key]) ? $options['handlers'][$key] : $key;
             $params[$key] = $this->_context->applyHandler($this, $method, $handler, $value, $options);
         }
         $strings = $this->_context->strings();
     }
     return String::insert(isset($strings[$string]) ? $strings[$string] : $string, $params);
 }