1 | <?php |
||
14 | class MarkdownRenderer |
||
15 | { |
||
16 | /** |
||
17 | * @var string |
||
18 | */ |
||
19 | protected $templatePath; |
||
20 | |||
21 | /** |
||
22 | * The Parsedown instance. |
||
23 | * |
||
24 | * @var \Parsedown |
||
25 | */ |
||
26 | protected $parsedown; |
||
27 | |||
28 | /** |
||
29 | * SlimRenderer constructor. |
||
30 | * |
||
31 | * @param string $templatePath |
||
32 | * @param parsedown $parseDown The instance to use to parse. |
||
33 | */ |
||
34 | 6 | public function __construct($templatePath = '', $parseDown = null) |
|
|
|||
35 | { |
||
36 | 6 | $this->templatePath = $templatePath; |
|
37 | 6 | $this->parsedown = new \Parsedown(); |
|
38 | 6 | } |
|
39 | |||
40 | /** |
||
41 | * Render a template. |
||
42 | * |
||
43 | * throws RuntimeException if $templatePath . $template does not exist |
||
44 | * |
||
45 | * @param ResponseInterface $response |
||
46 | * @param string $template |
||
47 | * |
||
48 | * @return ResponseInterface |
||
49 | * |
||
50 | * @throws \InvalidArgumentException |
||
51 | * @throws \RuntimeException |
||
52 | */ |
||
53 | 2 | public function render(ResponseInterface $response, $template) |
|
54 | { |
||
55 | 2 | $output = $this->fetch($template); |
|
56 | |||
57 | 1 | $response->getBody()->write($output); |
|
58 | |||
59 | 1 | return $response; |
|
60 | } |
||
61 | |||
62 | /** |
||
63 | * Get the template path. |
||
64 | * |
||
65 | * @return string |
||
66 | */ |
||
67 | 2 | public function getTemplatePath() |
|
71 | |||
72 | /** |
||
73 | * Set the template path. |
||
74 | * |
||
75 | * @param string $templatePath |
||
76 | */ |
||
77 | 1 | public function setTemplatePath($templatePath) |
|
81 | |||
82 | /** |
||
83 | * Get the parsedown. |
||
84 | * |
||
85 | * @return \Parsedown |
||
86 | */ |
||
87 | 2 | public function getParsedown() |
|
91 | |||
92 | /** |
||
93 | * Set the parsedown. |
||
94 | * |
||
95 | * @param \Parsedown |
||
96 | */ |
||
97 | 1 | public function setParsedown($parsedown) |
|
101 | |||
102 | /** |
||
103 | * Renders a template and returns the result as a string. |
||
104 | * |
||
105 | * throws RuntimeException if $templatePath . $template does not exist |
||
106 | * |
||
107 | * @param $template |
||
108 | * |
||
109 | * @return mixed |
||
110 | * |
||
111 | * @throws \InvalidArgumentException |
||
112 | * @throws \RuntimeException |
||
113 | */ |
||
114 | 2 | public function fetch($template) |
|
123 | } |
||
124 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.