1 | <?php |
||
19 | class MarkdownRenderer extends AbstractRenderer |
||
20 | { |
||
21 | public $indent = ' '; |
||
22 | |||
23 | /** |
||
24 | * {@inheritdoc} |
||
25 | */ |
||
26 | 2 | public function render(History $history) |
|
27 | { |
||
28 | 2 | $this->setHistory($history); |
|
29 | |||
30 | 2 | return $this->renderSparse([ |
|
31 | 2 | $this->renderHeaders(), |
|
32 | 2 | $this->renderTags(), |
|
33 | 2 | $this->renderLinks(), |
|
34 | ]); |
||
35 | } |
||
36 | |||
37 | 2 | public function renderHeaders() |
|
41 | |||
42 | 2 | public function renderTags() |
|
46 | |||
47 | 2 | public function renderLinks() |
|
51 | |||
52 | 2 | public function renderObjects($method, $objects, $sparse = false) |
|
53 | { |
||
54 | 2 | $res = []; |
|
55 | 2 | foreach ($objects as $key => $value) { |
|
56 | 2 | $res[$key] = call_user_func([$this, $method], $value, $key); |
|
57 | } |
||
58 | |||
59 | 2 | return $this->renderText($res, $sparse); |
|
60 | } |
||
61 | |||
62 | 2 | public function renderSparse(array $lines) |
|
68 | |||
69 | 2 | public function renderText(array $lines, $sparse = false) |
|
70 | { |
||
71 | 2 | if (!$sparse) { |
|
72 | 2 | foreach ($lines as &$line) { |
|
73 | 2 | $line = rtrim($line); |
|
74 | } |
||
75 | 2 | $lines = array_filter($lines); |
|
76 | } |
||
77 | |||
78 | 2 | return $this->renderSparse($lines); |
|
79 | } |
||
80 | |||
81 | 2 | public function renderLink($href, $link) |
|
85 | |||
86 | public function renderHeader($header) |
||
90 | |||
91 | 2 | public function renderTag(Tag $tag) |
|
92 | { |
||
93 | 2 | return $this->renderSparse([ |
|
94 | 2 | $this->renderTagHead($tag), |
|
95 | 2 | $this->renderObjects('renderNote', $tag->getNotes()), |
|
96 | ]); |
||
97 | } |
||
98 | |||
99 | 2 | public function renderTagHead(Tag $tag) |
|
100 | { |
||
101 | 2 | $res = '## [' . $tag->getName() . ']'; |
|
102 | 2 | if ($tag->getDate()) { |
|
|
|||
103 | 2 | $res .= ' - ' . $tag->getDate(); |
|
104 | } |
||
105 | |||
106 | 2 | return $res . "\n"; |
|
107 | } |
||
108 | |||
109 | 2 | public function renderNote(Note $note) |
|
110 | { |
||
111 | 2 | return $this->renderText([ |
|
112 | 2 | $this->renderNoteHead($note), |
|
113 | 2 | $this->renderObjects('renderCommit', $note->getCommits()), |
|
114 | ]); |
||
115 | } |
||
116 | |||
117 | 2 | public function renderNoteHead(Note $note) |
|
121 | |||
122 | 2 | public function renderCommit(Commit $commit) |
|
123 | { |
||
124 | 2 | return $this->renderText([ |
|
125 | 2 | $this->renderCommitHead($commit), |
|
126 | 2 | $this->renderText($commit->getComments()), |
|
127 | ]); |
||
128 | } |
||
129 | |||
130 | 2 | public function renderCommitHead(Commit $commit) |
|
134 | } |
||
135 |
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
string
values, the empty string''
is a special case, in particular the following results might be unexpected: