1 | <?php |
||
23 | class MarkdownRenderer extends AbstractRenderer |
||
24 | { |
||
25 | public $indent = ' '; |
||
26 | |||
27 | /** |
||
28 | * {@inheritdoc} |
||
29 | */ |
||
30 | 2 | public function render(History $history) |
|
31 | { |
||
32 | 2 | $this->setHistory($history); |
|
33 | |||
34 | 2 | return $this->renderSparse([ |
|
35 | 2 | $this->renderHeaders(), |
|
36 | 2 | $this->renderTags(), |
|
37 | 2 | $this->renderLinks(), |
|
38 | ]); |
||
39 | } |
||
40 | |||
41 | 2 | public function renderHeaders() |
|
45 | |||
46 | 2 | public function renderTags() |
|
50 | |||
51 | 2 | public function renderLinks($links = null) |
|
52 | { |
||
53 | 2 | if ($links === null) { |
|
54 | 2 | $links = $this->getHistory()->getLinks(); |
|
55 | } |
||
56 | |||
57 | 2 | return $this->renderObjects('renderLink', $links); |
|
58 | } |
||
59 | |||
60 | 2 | public function renderObjects($method, $objects, $sparse = false) |
|
61 | { |
||
62 | 2 | $res = []; |
|
63 | 2 | foreach ($objects as $key => $value) { |
|
64 | 2 | $res[$key] = call_user_func([$this, $method], $value, $key); |
|
65 | } |
||
66 | |||
67 | 2 | return $this->renderText($res, $sparse); |
|
68 | } |
||
69 | |||
70 | 2 | public function renderSparse(array $lines) |
|
76 | |||
77 | 2 | public function renderText(array $lines, $sparse = false) |
|
78 | { |
||
79 | 2 | if (!$sparse) { |
|
80 | 2 | foreach ($lines as &$line) { |
|
81 | 2 | $line = rtrim($line); |
|
82 | } |
||
83 | 2 | $lines = array_filter($lines); |
|
84 | } |
||
85 | |||
86 | 2 | return $this->renderSparse($lines); |
|
87 | } |
||
88 | |||
89 | 2 | public function renderLink($href, $link) |
|
93 | |||
94 | public function renderHeader($header) |
||
98 | |||
99 | 2 | public function renderTag(Tag $tag) |
|
100 | { |
||
101 | 2 | return $this->renderSparse([ |
|
102 | 2 | $this->renderTagHead($tag), |
|
103 | 2 | $this->renderObjects('renderNote', $tag->getNotes()), |
|
104 | ]); |
||
105 | } |
||
106 | |||
107 | 2 | public function renderTagHead(Tag $tag) |
|
108 | { |
||
109 | 2 | $res = '## [' . $tag->getName() . ']'; |
|
110 | 2 | if ($tag->getDate()) { |
|
|
|||
111 | 2 | $res .= ' - ' . $tag->getDate(); |
|
112 | } |
||
113 | |||
114 | 2 | return $res . "\n"; |
|
115 | } |
||
116 | |||
117 | 2 | public function renderNote(Note $note) |
|
118 | { |
||
119 | 2 | return $this->renderText([ |
|
120 | 2 | $this->renderNoteHead($note), |
|
121 | 2 | $this->renderObjects('renderCommit', $note->getCommits()), |
|
122 | ]); |
||
123 | } |
||
124 | |||
125 | 2 | public function renderNoteHead(Note $note) |
|
129 | |||
130 | 2 | public function renderCommit(Commit $commit) |
|
131 | { |
||
132 | 2 | return $this->renderText([ |
|
133 | 2 | $this->renderCommitHead($commit), |
|
134 | 2 | $this->renderText($commit->getComments()), |
|
135 | ]); |
||
136 | } |
||
137 | |||
138 | 2 | public function renderCommitHead(Commit $commit) |
|
142 | } |
||
143 |
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: