1 | <?php |
||
15 | class MarkdownRenderer |
||
16 | { |
||
17 | /** |
||
18 | * @var string |
||
19 | */ |
||
20 | protected $templatePath; |
||
21 | |||
22 | /** |
||
23 | * The Parsedown instance. |
||
24 | * |
||
25 | * @var \Parsedown |
||
26 | */ |
||
27 | protected $parsedown; |
||
28 | |||
29 | /** |
||
30 | * SlimRenderer constructor. |
||
31 | * |
||
32 | * @param string $templatePath |
||
33 | * @param \Parsedown $parsedown The instance to use to parse. |
||
34 | */ |
||
35 | 7 | public function __construct($templatePath = '', $parsedown = null) |
|
36 | { |
||
37 | 7 | $this->templatePath = $templatePath; |
|
38 | 7 | if ($parsedown === null) { |
|
39 | 6 | $this->parsedown = new \Parsedown(); |
|
40 | } else { |
||
41 | 1 | $this->parsedown = $parsedown; |
|
42 | } |
||
43 | 7 | } |
|
44 | |||
45 | /** |
||
46 | * Render a template. |
||
47 | * |
||
48 | * throws RuntimeException if $templatePath . $template does not exist |
||
49 | * |
||
50 | * @param ResponseInterface $response |
||
51 | * @param string $template |
||
52 | * |
||
53 | * @throws \InvalidArgumentException |
||
54 | * @throws \RuntimeException |
||
55 | * |
||
56 | * @return ResponseInterface |
||
57 | */ |
||
58 | 3 | public function render(ResponseInterface $response, $template) |
|
66 | |||
67 | /** |
||
68 | * Get the template path. |
||
69 | * |
||
70 | * @return string |
||
71 | */ |
||
72 | 2 | public function getTemplatePath() |
|
76 | |||
77 | /** |
||
78 | * Set the template path. |
||
79 | * |
||
80 | * @param string $templatePath |
||
81 | */ |
||
82 | 1 | public function setTemplatePath($templatePath) |
|
86 | |||
87 | /** |
||
88 | * Get the parsedown. |
||
89 | * |
||
90 | * @return \Parsedown |
||
91 | */ |
||
92 | 2 | public function getParsedown() |
|
96 | |||
97 | /** |
||
98 | * Set the parsedown. |
||
99 | * |
||
100 | * @param \Parsedown |
||
101 | */ |
||
102 | 1 | public function setParsedown($parsedown) |
|
106 | |||
107 | /** |
||
108 | * Renders a template and returns the result as a string. |
||
109 | * |
||
110 | * throws RuntimeException if $templatePath . $template does not exist |
||
111 | * |
||
112 | * @param $template |
||
113 | * |
||
114 | * @throws \InvalidArgumentException |
||
115 | * @throws \RuntimeException |
||
116 | * |
||
117 | * @return mixed |
||
118 | */ |
||
119 | 3 | public function fetch($template) |
|
128 | } |
||
129 |