55use League \CommonMark \DocParser ;
66use League \CommonMark \Environment ;
77use Markdom \Dispatcher \CommonmarkUtil \DocumentProcessor ;
8- use Markdom \Dispatcher \Exception \DispatcherException ;
98use Markdom \Dispatcher \HtmlProcessor \HtmlProcessorInterface ;
9+ use Markdom \DispatcherInterface \DispatcherInterface ;
1010use Markdom \HandlerInterface \HandlerInterface ;
1111
1212/**
1313 * Class CommonmarkDispatcher
1414 *
1515 * @package Markdom\Dispatcher
1616 */
17- class CommonmarkDispatcher extends AbstractDispatcher
17+ class CommonmarkDispatcher implements DispatcherInterface
1818{
1919
2020 /**
21- * @var HandlerInterface
21+ * @var HtmlProcessorInterface
2222 */
23- private $ markdomHandler ;
23+ private $ htmlProcessor = null ;
2424
2525 /**
26- * @var HtmlProcessorInterface
26+ * @var string
2727 */
28- private $ htmlProcessor = null ;
28+ private $ commonmarkString ;
2929
3030 /**
31- * Parser constructor.
31+ * CommonmarkDispatcher constructor.
3232 *
33- * @param HandlerInterface $commonmarkHandler
33+ * @param string $commonmarkString
3434 */
35- public function __construct (HandlerInterface $ commonmarkHandler )
35+ public function __construct ($ commonmarkString )
3636 {
37- $ this ->markdomHandler = $ commonmarkHandler ;
37+ $ this ->commonmarkString = $ commonmarkString ;
3838 }
3939
4040 /**
@@ -56,34 +56,26 @@ public function setHtmlProcessor($htmlProcessor)
5656 }
5757
5858 /**
59- * @param string $sourceFile
60- * @return $this
61- * @throws DispatcherException
59+ * @return bool
6260 */
63- public function processFile ( $ sourceFile )
61+ public function isReusable ( )
6462 {
65- if (!file_exists ($ sourceFile )) {
66- throw new DispatcherException ('Source file not found ' );
67- }
68- if (!is_readable ($ sourceFile )) {
69- throw new DispatcherException ('Source file not readable ' );
70- }
71- return $ this ->process (file_get_contents ($ sourceFile ));
63+ return true ;
7264 }
7365
7466 /**
75- * @param string $source
76- * @return $this
67+ * @param HandlerInterface $markdomHandler
68+ * @return mixed
7769 */
78- public function process ( $ source )
70+ public function dispatchTo ( HandlerInterface $ markdomHandler )
7971 {
8072 $ commonMarkEnvironment = Environment::createCommonMarkEnvironment ();
8173 $ commonMarkEnvironment ->addDocumentProcessor (
82- new DocumentProcessor ($ this -> markdomHandler , $ this -> getDispatchCommentBlocks () , $ this ->htmlProcessor )
74+ new DocumentProcessor ($ markdomHandler , $ this ->htmlProcessor )
8375 );
8476 $ docParser = new DocParser ($ commonMarkEnvironment );
85- $ docParser ->parse ($ source );
86- return $ this ;
77+ $ docParser ->parse ($ this -> commonmarkString );
78+ return $ markdomHandler -> getResult () ;
8779 }
8880
8981}
0 commit comments