File indexing completed on 2024-04-28 06:00:02

0001 <?php
0002 /**
0003  * Zend Framework
0004  *
0005  * LICENSE
0006  *
0007  * This source file is subject to the new BSD license that is bundled
0008  * with this package in the file LICENSE.txt.
0009  * It is also available through the world-wide-web at this URL:
0010  * http://framework.zend.com/license/new-bsd
0011  * If you did not receive a copy of the license and are unable to
0012  * obtain it through the world-wide-web, please send an email
0013  * to license@zend.com so we can send you a copy immediately.
0014  *
0015  * @category   Zend
0016  * @package    Zend_Markup
0017  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0018  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0019  * @version    $Id$
0020  */
0021 
0022 /**
0023  * @see Zend_Loader_PluginLoader
0024  */
0025 // require_once 'Zend/Loader/PluginLoader.php';
0026 
0027 /**
0028  * @category   Zend
0029  * @package    Zend_Markup
0030  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0031  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0032  */
0033 class Zend_Markup
0034 {
0035     const CALLBACK = 'callback';
0036     const REPLACE  = 'replace';
0037 
0038 
0039     /**
0040      * The parser loader
0041      *
0042      * @var Zend_Loader_PluginLoader
0043      */
0044     protected static $_parserLoader;
0045 
0046     /**
0047      * The renderer loader
0048      *
0049      * @var Zend_Loader_PluginLoader
0050      */
0051     protected static $_rendererLoader;
0052 
0053 
0054     /**
0055      * Disable instantiation of Zend_Markup
0056      */
0057     private function __construct() { }
0058 
0059     /**
0060      * Get the parser loader
0061      *
0062      * @return Zend_Loader_PluginLoader
0063      */
0064     public static function getParserLoader()
0065     {
0066         if (!(self::$_parserLoader instanceof Zend_Loader_PluginLoader)) {
0067             self::$_parserLoader = new Zend_Loader_PluginLoader(array(
0068                 'Zend_Markup_Parser' => 'Zend/Markup/Parser/',
0069             ));
0070         }
0071 
0072         return self::$_parserLoader;
0073     }
0074 
0075     /**
0076      * Get the renderer loader
0077      *
0078      * @return Zend_Loader_PluginLoader
0079      */
0080     public static function getRendererLoader()
0081     {
0082         if (!(self::$_rendererLoader instanceof Zend_Loader_PluginLoader)) {
0083             self::$_rendererLoader = new Zend_Loader_PluginLoader(array(
0084                 'Zend_Markup_Renderer' => 'Zend/Markup/Renderer/',
0085             ));
0086         }
0087 
0088         return self::$_rendererLoader;
0089     }
0090 
0091     /**
0092      * Add a parser path
0093      *
0094      * @param  string $prefix
0095      * @param  string $path
0096      * @return Zend_Loader_PluginLoader
0097      */
0098     public static function addParserPath($prefix, $path)
0099     {
0100         return self::getParserLoader()->addPrefixPath($prefix, $path);
0101     }
0102 
0103     /**
0104      * Add a renderer path
0105      *
0106      * @param  string $prefix
0107      * @param  string $path
0108      * @return Zend_Loader_PluginLoader
0109      */
0110     public static function addRendererPath($prefix, $path)
0111     {
0112         return self::getRendererLoader()->addPrefixPath($prefix, $path);
0113     }
0114 
0115     /**
0116      * Factory pattern
0117      *
0118      * @param  string $parser
0119      * @param  string $renderer
0120      * @param  array $options
0121      * @return Zend_Markup_Renderer_RendererAbstract
0122      */
0123     public static function factory($parser, $renderer = 'Html', array $options = array())
0124     {
0125         $parserClass   = self::getParserLoader()->load($parser);
0126         $rendererClass = self::getRendererLoader()->load($renderer);
0127 
0128         $parser            = new $parserClass();
0129         $options['parser'] = $parser;
0130         $renderer          = new $rendererClass($options);
0131 
0132         return $renderer;
0133     }
0134 }