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