Latte\Runtime\Filters::getConvertor PHP Метод

getConvertor() публичный статический Метод

public static getConvertor ( $source, $dest ) : callable
Результат callable
    public static function getConvertor($source, $dest)
    {
        static $table = [Engine::CONTENT_TEXT => ['html' => 'escapeHtmlText', 'xhtml' => 'escapeHtmlText', 'htmlAttr' => 'escapeHtmlAttr', 'xhtmlAttr' => 'escapeHtmlAttr', 'htmlAttrJs' => 'escapeHtmlAttr', 'xhtmlAttrJs' => 'escapeHtmlAttr', 'htmlAttrCss' => 'escapeHtmlAttr', 'xhtmlAttrCss' => 'escapeHtmlAttr', 'htmlAttrUrl' => 'escapeHtmlAttr', 'xhtmlAttrUrl' => 'escapeHtmlAttr', 'htmlComment' => 'escapeHtmlComment', 'xhtmlComment' => 'escapeHtmlComment', 'xml' => 'escapeXml', 'xmlAttr' => 'escapeXml'], Engine::CONTENT_JS => ['html' => 'escapeHtmlText', 'xhtml' => 'escapeHtmlText', 'htmlAttr' => 'escapeHtmlAttr', 'xhtmlAttr' => 'escapeHtmlAttr', 'htmlAttrJs' => 'escapeHtmlAttr', 'xhtmlAttrJs' => 'escapeHtmlAttr', 'htmlJs' => 'escapeHtmlRawText', 'xhtmlJs' => 'escapeHtmlRawText', 'htmlComment' => 'escapeHtmlComment', 'xhtmlComment' => 'escapeHtmlComment'], Engine::CONTENT_CSS => ['html' => 'escapeHtmlText', 'xhtml' => 'escapeHtmlText', 'htmlAttr' => 'escapeHtmlAttr', 'xhtmlAttr' => 'escapeHtmlAttr', 'htmlAttrCss' => 'escapeHtmlAttr', 'xhtmlAttrCss' => 'escapeHtmlAttr', 'htmlCss' => 'escapeHtmlRawText', 'xhtmlCss' => 'escapeHtmlRawText', 'htmlComment' => 'escapeHtmlComment', 'xhtmlComment' => 'escapeHtmlComment'], Engine::CONTENT_HTML => ['htmlAttr' => 'escapeHtmlAttrConv', 'htmlAttrJs' => 'escapeHtmlAttrConv', 'htmlAttrCss' => 'escapeHtmlAttrConv', 'htmlAttrUrl' => 'escapeHtmlAttrConv', 'htmlComment' => 'escapeHtmlComment'], Engine::CONTENT_XHTML => ['xhtmlAttr' => 'escapeHtmlAttrConv', 'xhtmlAttrJs' => 'escapeHtmlAttrConv', 'xhtmlAttrCss' => 'escapeHtmlAttrConv', 'xhtmlAttrUrl' => 'escapeHtmlAttrConv', 'xhtmlComment' => 'escapeHtmlComment']];
        return isset($table[$source][$dest]) ? [__CLASS__, $table[$source][$dest]] : NULL;
    }

Usage Example

Пример #1
0
 /**
  * Renders block.
  * @param  string
  * @param  array
  * @param  string|\Closure content-type name or modifier closure
  * @return void
  * @internal
  */
 protected function renderBlock($name, array $params, $mod = NULL)
 {
     if (empty($this->blockQueue[$name])) {
         $hint = isset($this->blockQueue) && ($t = Latte\Helpers::getSuggestion(array_keys($this->blockQueue), $name)) ? ", did you mean '{$t}'?" : '.';
         throw new \RuntimeException("Cannot include undefined block '{$name}'{$hint}");
     }
     $block = reset($this->blockQueue[$name]);
     if ($mod && $mod !== ($blockType = $this->blockTypes[$name])) {
         if ($filter = is_string($mod) ? Filters::getConvertor($blockType, $mod) : $mod) {
             echo $filter($this->capture(function () use($block, $params) {
                 $block($params);
             }), $blockType);
             return;
         }
         trigger_error("Including block {$name} with content type " . strtoupper($blockType) . ' into incompatible type ' . strtoupper($mod) . '.', E_USER_WARNING);
     }
     $block($params);
 }