Markup.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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-2015 Zend Technologies USA Inc. (http://www.zend.com)
  18. * @license http://framework.zend.com/license/new-bsd New BSD License
  19. * @version $Id$
  20. */
  21. /**
  22. * @see Zend_Loader_PluginLoader
  23. */
  24. require_once 'Zend/Loader/PluginLoader.php';
  25. /**
  26. * @category Zend
  27. * @package Zend_Markup
  28. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  29. * @license http://framework.zend.com/license/new-bsd New BSD License
  30. */
  31. class Zend_Markup
  32. {
  33. const CALLBACK = 'callback';
  34. const REPLACE = 'replace';
  35. /**
  36. * The parser loader
  37. *
  38. * @var Zend_Loader_PluginLoader
  39. */
  40. protected static $_parserLoader;
  41. /**
  42. * The renderer loader
  43. *
  44. * @var Zend_Loader_PluginLoader
  45. */
  46. protected static $_rendererLoader;
  47. /**
  48. * Disable instantiation of Zend_Markup
  49. */
  50. private function __construct() { }
  51. /**
  52. * Get the parser loader
  53. *
  54. * @return Zend_Loader_PluginLoader
  55. */
  56. public static function getParserLoader()
  57. {
  58. if (!(self::$_parserLoader instanceof Zend_Loader_PluginLoader)) {
  59. self::$_parserLoader = new Zend_Loader_PluginLoader(array(
  60. 'Zend_Markup_Parser' => 'Zend/Markup/Parser/',
  61. ));
  62. }
  63. return self::$_parserLoader;
  64. }
  65. /**
  66. * Get the renderer loader
  67. *
  68. * @return Zend_Loader_PluginLoader
  69. */
  70. public static function getRendererLoader()
  71. {
  72. if (!(self::$_rendererLoader instanceof Zend_Loader_PluginLoader)) {
  73. self::$_rendererLoader = new Zend_Loader_PluginLoader(array(
  74. 'Zend_Markup_Renderer' => 'Zend/Markup/Renderer/',
  75. ));
  76. }
  77. return self::$_rendererLoader;
  78. }
  79. /**
  80. * Add a parser path
  81. *
  82. * @param string $prefix
  83. * @param string $path
  84. * @return Zend_Loader_PluginLoader
  85. */
  86. public static function addParserPath($prefix, $path)
  87. {
  88. return self::getParserLoader()->addPrefixPath($prefix, $path);
  89. }
  90. /**
  91. * Add a renderer path
  92. *
  93. * @param string $prefix
  94. * @param string $path
  95. * @return Zend_Loader_PluginLoader
  96. */
  97. public static function addRendererPath($prefix, $path)
  98. {
  99. return self::getRendererLoader()->addPrefixPath($prefix, $path);
  100. }
  101. /**
  102. * Factory pattern
  103. *
  104. * @param string $parser
  105. * @param string $renderer
  106. * @param array $options
  107. * @return Zend_Markup_Renderer_RendererAbstract
  108. */
  109. public static function factory($parser, $renderer = 'Html', array $options = array())
  110. {
  111. $parserClass = self::getParserLoader()->load($parser);
  112. $rendererClass = self::getRendererLoader()->load($renderer);
  113. $parser = new $parserClass();
  114. $options['parser'] = $parser;
  115. $renderer = new $rendererClass($options);
  116. return $renderer;
  117. }
  118. }