Skip to content

Commit 508fef6

Browse files
author
Martin Brecht-Precht
committed
Updated dependencies.
1 parent b764ae2 commit 508fef6

20 files changed

+225
-166
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
},
2525
"require": {
2626
"php": ">=5.3",
27-
"markdom/handler-interface": "^1.0.9",
27+
"markdom/handler-interface": "^1.0.10",
2828
"markenwerk/stack-util": "~1.0",
2929
"markenwerk/string-builder": "^1.0.4",
3030
"markenwerk/json-pretty-printer": "~1.0",

example/commonmark-01.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
require_once(__DIR__ . '/../vendor/autoload.php');
99

1010
$handler = new CommonmarkHandler();
11-
$dispatcher = new JsonDispatcher($handler);
12-
$dispatcher
13-
->setDispatchCommentBlocks(false)
14-
->processFile(__DIR__ . '/example-data.json');
11+
$dispatcher = new JsonDispatcher(file_get_contents(__DIR__ . '/example-data.json'));
12+
$dispatcher->dispatchTo($handler);
1513
fwrite(STDOUT, $handler->getResult());

example/commonmark-02.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@
88
require_once(__DIR__ . '/../vendor/autoload.php');
99

1010
$handler = new CommonmarkHandler();
11-
$dispatcher = new CommonmarkDispatcher($handler);
12-
$dispatcher->processFile(__DIR__ . '/example-data.md');
11+
$dispatcher = new CommonmarkDispatcher(file_get_contents(__DIR__ . '/example-data.md'));
12+
$dispatcher->dispatchTo($handler);
1313
fwrite(STDOUT, $handler->getResult());

example/debug.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@
88
require_once(__DIR__ . '/../vendor/autoload.php');
99

1010
$handler = new DebugHandler();
11-
$dispatcher = new JsonDispatcher($handler);
12-
$dispatcher->processFile(__DIR__ . '/example-data.json');
11+
$dispatcher = new JsonDispatcher(file_get_contents(__DIR__ . '/example-data.json'));
12+
$dispatcher->dispatchTo($handler);
1313
fwrite(STDOUT, $handler->getResult());

example/html.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@
1111
$handler
1212
->setEscapeHtml(false)
1313
->setBreakSoftBreaks(false);
14-
$dispatcher = new JsonDispatcher($handler);
15-
$dispatcher->processFile(__DIR__ . '/example-data.json');
14+
$dispatcher = new JsonDispatcher(file_get_contents(__DIR__ . '/example-data.json'));
15+
$dispatcher->dispatchTo($handler);
1616
fwrite(STDOUT, $handler->getResult());

example/json.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@
1111
$handler
1212
->setPrettyPrint(true)
1313
->setEscapeUnicode(true);
14-
$dispatcher = new JsonDispatcher($handler);
15-
$dispatcher->processFile(__DIR__ . '/example-data.json');
14+
$dispatcher = new JsonDispatcher(file_get_contents(__DIR__ . '/example-data.json'));
15+
$dispatcher->dispatchTo($handler);
1616
fwrite(STDOUT, $handler->getResult());

example/xhtml.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@
1111
$handler
1212
->setEscapeHtml(true)
1313
->setBreakSoftBreaks(true);
14-
$dispatcher = new JsonDispatcher($handler);
15-
$dispatcher->processFile(__DIR__ . '/example-data.json');
14+
$dispatcher = new JsonDispatcher(file_get_contents(__DIR__ . '/example-data.json'));
15+
$dispatcher->dispatchTo($handler);
1616
fwrite(STDOUT, $handler->getResult());

example/xml.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@
1010
$handler = new XmlHandler();
1111
$handler
1212
->setPrettyPrint(true);
13-
$dispatcher = new JsonDispatcher($handler);
14-
$dispatcher->processFile(__DIR__ . '/example-data.json');
13+
$dispatcher = new JsonDispatcher(file_get_contents(__DIR__ . '/example-data.json'));
14+
$dispatcher->dispatchTo($handler);
1515
fwrite(STDOUT, $handler->getResult()->saveXML());

src/Dispatcher/AbstractDispatcher.php

Lines changed: 0 additions & 38 deletions
This file was deleted.

src/Dispatcher/CommonmarkDispatcher.php

Lines changed: 19 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,36 +5,36 @@
55
use League\CommonMark\DocParser;
66
use League\CommonMark\Environment;
77
use Markdom\Dispatcher\CommonmarkUtil\DocumentProcessor;
8-
use Markdom\Dispatcher\Exception\DispatcherException;
98
use Markdom\Dispatcher\HtmlProcessor\HtmlProcessorInterface;
9+
use Markdom\DispatcherInterface\DispatcherInterface;
1010
use 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

Comments
 (0)