web/enmi/Zend/Markup.php
changeset 19 1c2f13fd785c
parent 0 4eba9c11703f
equal deleted inserted replaced
18:bd595ad770fc 19:1c2f13fd785c
       
     1 <?php
       
     2 /**
       
     3  * Zend Framework
       
     4  *
       
     5  * LICENSE
       
     6  *
       
     7  * This source file is subject to the new BSD license that is bundled
       
     8  * with this package in the file LICENSE.txt.
       
     9  * It is also available through the world-wide-web at this URL:
       
    10  * http://framework.zend.com/license/new-bsd
       
    11  * If you did not receive a copy of the license and are unable to
       
    12  * obtain it through the world-wide-web, please send an email
       
    13  * to license@zend.com so we can send you a copy immediately.
       
    14  *
       
    15  * @category   Zend
       
    16  * @package    Zend_Markup
       
    17  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
       
    18  * @license    http://framework.zend.com/license/new-bsd     New BSD License
       
    19  * @version    $Id: Markup.php 20277 2010-01-14 14:17:12Z kokx $
       
    20  */
       
    21 
       
    22 /**
       
    23  * @see Zend_Loader_PluginLoader
       
    24  */
       
    25 require_once 'Zend/Loader/PluginLoader.php';
       
    26 
       
    27 /**
       
    28  * @category   Zend
       
    29  * @package    Zend_Markup
       
    30  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
       
    31  * @license    http://framework.zend.com/license/new-bsd     New BSD License
       
    32  */
       
    33 class Zend_Markup
       
    34 {
       
    35     const CALLBACK = 'callback';
       
    36     const REPLACE  = 'replace';
       
    37 
       
    38 
       
    39     /**
       
    40      * The parser loader
       
    41      *
       
    42      * @var Zend_Loader_PluginLoader
       
    43      */
       
    44     protected static $_parserLoader;
       
    45 
       
    46     /**
       
    47      * The renderer loader
       
    48      *
       
    49      * @var Zend_Loader_PluginLoader
       
    50      */
       
    51     protected static $_rendererLoader;
       
    52 
       
    53 
       
    54     /**
       
    55      * Disable instantiation of Zend_Markup
       
    56      */
       
    57     private function __construct() { }
       
    58 
       
    59     /**
       
    60      * Get the parser loader
       
    61      *
       
    62      * @return Zend_Loader_PluginLoader
       
    63      */
       
    64     public static function getParserLoader()
       
    65     {
       
    66         if (!(self::$_parserLoader instanceof Zend_Loader_PluginLoader)) {
       
    67             self::$_parserLoader = new Zend_Loader_PluginLoader(array(
       
    68                 'Zend_Markup_Parser' => 'Zend/Markup/Parser/',
       
    69             ));
       
    70         }
       
    71 
       
    72         return self::$_parserLoader;
       
    73     }
       
    74 
       
    75     /**
       
    76      * Get the renderer loader
       
    77      *
       
    78      * @return Zend_Loader_PluginLoader
       
    79      */
       
    80     public static function getRendererLoader()
       
    81     {
       
    82         if (!(self::$_rendererLoader instanceof Zend_Loader_PluginLoader)) {
       
    83             self::$_rendererLoader = new Zend_Loader_PluginLoader(array(
       
    84                 'Zend_Markup_Renderer' => 'Zend/Markup/Renderer/',
       
    85             ));
       
    86         }
       
    87 
       
    88         return self::$_rendererLoader;
       
    89     }
       
    90 
       
    91     /**
       
    92      * Add a parser path
       
    93      *
       
    94      * @param  string $prefix
       
    95      * @param  string $path
       
    96      * @return Zend_Loader_PluginLoader
       
    97      */
       
    98     public static function addParserPath($prefix, $path)
       
    99     {
       
   100         return self::getParserLoader()->addPrefixPath($prefix, $path);
       
   101     }
       
   102 
       
   103     /**
       
   104      * Add a renderer path
       
   105      *
       
   106      * @param  string $prefix
       
   107      * @param  string $path
       
   108      * @return Zend_Loader_PluginLoader
       
   109      */
       
   110     public static function addRendererPath($prefix, $path)
       
   111     {
       
   112         return self::getRendererLoader()->addPrefixPath($prefix, $path);
       
   113     }
       
   114 
       
   115     /**
       
   116      * Factory pattern
       
   117      *
       
   118      * @param  string $parser
       
   119      * @param  string $renderer
       
   120      * @param  array $options
       
   121      * @return Zend_Markup_Renderer_RendererAbstract
       
   122      */
       
   123     public static function factory($parser, $renderer = 'Html', array $options = array())
       
   124     {
       
   125         $parserClass   = self::getParserLoader()->load($parser);
       
   126         $rendererClass = self::getRendererLoader()->load($renderer);
       
   127 
       
   128         $parser            = new $parserClass();
       
   129         $options['parser'] = $parser;
       
   130         $renderer          = new $rendererClass($options);
       
   131 
       
   132         return $renderer;
       
   133     }
       
   134 }