[ Index ]

PHP Cross Reference of phpBB-3.3.14-deutsch

title

Body

[close]

/vendor/s9e/text-formatter/src/ -> Bundle.php (source)

   1  <?php
   2  
   3  /**
   4  * @package   s9e\TextFormatter
   5  * @copyright Copyright (c) 2010-2022 The s9e authors
   6  * @license   http://www.opensource.org/licenses/mit-license.php The MIT License
   7  */
   8  namespace s9e\TextFormatter;
   9  
  10  abstract class Bundle
  11  {
  12      /**
  13      * Return a cached instance of the parser
  14      *
  15      * @return Parser
  16      */
  17  	public static function getCachedParser()
  18      {
  19          if (!isset(static::$parser))
  20          {
  21              static::$parser = static::getParser();
  22          }
  23  
  24          return static::$parser;
  25      }
  26  
  27      /**
  28      * Return a cached instance of the renderer
  29      *
  30      * @return Renderer
  31      */
  32  	public static function getCachedRenderer()
  33      {
  34          if (!isset(static::$renderer))
  35          {
  36              static::$renderer = static::getRenderer();
  37          }
  38  
  39          return static::$renderer;
  40      }
  41  
  42      /**
  43      * Return a new instance of s9e\TextFormatter\Parser
  44      *
  45      * @return Parser
  46      */
  47      abstract public static function getParser();
  48  
  49      /**
  50      * Return a new instance of s9e\TextFormatter\Renderer
  51      *
  52      * @return Renderer
  53      */
  54      abstract public static function getRenderer();
  55  
  56      /**
  57      * Return the source of the JavaScript parser if available
  58      *
  59      * @return string
  60      */
  61  	public static function getJS()
  62      {
  63          return '';
  64      }
  65  
  66      /**
  67      * Parse given text using a singleton instance of the bundled Parser
  68      *
  69      * @param  string $text Original text
  70      * @return string       Intermediate representation
  71      */
  72  	public static function parse($text)
  73      {
  74          if (isset(static::$beforeParse))
  75          {
  76              $text = call_user_func(static::$beforeParse, $text);
  77          }
  78  
  79          $xml = static::getCachedParser()->parse($text);
  80  
  81          if (isset(static::$afterParse))
  82          {
  83              $xml = call_user_func(static::$afterParse, $xml);
  84          }
  85  
  86          return $xml;
  87      }
  88  
  89      /**
  90      * Render an intermediate representation using a singleton instance of the bundled Renderer
  91      *
  92      * @param  string $xml    Intermediate representation
  93      * @param  array  $params Stylesheet parameters
  94      * @return string         Rendered result
  95      */
  96  	public static function render($xml, array $params = [])
  97      {
  98          $renderer = static::getCachedRenderer();
  99  
 100          if (!empty($params))
 101          {
 102              $renderer->setParameters($params);
 103          }
 104  
 105          if (isset(static::$beforeRender))
 106          {
 107              $xml = call_user_func(static::$beforeRender, $xml);
 108          }
 109  
 110          $output = $renderer->render($xml);
 111  
 112          if (isset(static::$afterRender))
 113          {
 114              $output = call_user_func(static::$afterRender, $output);
 115          }
 116  
 117          return $output;
 118      }
 119  
 120      /**
 121      * Reset the cached parser and renderer
 122      *
 123      * @return void
 124      */
 125  	public static function reset()
 126      {
 127          static::$parser   = null;
 128          static::$renderer = null;
 129      }
 130  
 131      /**
 132      * Transform an intermediate representation back to its original form
 133      *
 134      * @param  string $xml Intermediate representation
 135      * @return string      Original text
 136      */
 137  	public static function unparse($xml)
 138      {
 139          if (isset(static::$beforeUnparse))
 140          {
 141              $xml = call_user_func(static::$beforeUnparse, $xml);
 142          }
 143  
 144          $text = Unparser::unparse($xml);
 145  
 146          if (isset(static::$afterUnparse))
 147          {
 148              $text = call_user_func(static::$afterUnparse, $text);
 149          }
 150  
 151          return $text;
 152      }
 153  }


Generated: Mon Nov 25 19:05:08 2024 Cross-referenced by PHPXref 0.7.1