1 | <?php |
||
20 | class ReadmeController extends \hidev\controllers\TemplateController |
||
21 | { |
||
22 | /** |
||
23 | * @var \Twig_Environment |
||
24 | */ |
||
25 | protected $_twig; |
||
26 | |||
27 | /** |
||
28 | * @var array list of sections to render |
||
29 | */ |
||
30 | protected $_sections; |
||
31 | |||
32 | /** |
||
33 | * Get charset. |
||
34 | * @return string |
||
35 | */ |
||
36 | public function getCharset() |
||
37 | { |
||
38 | return (isset(Yii::$app->charset) ? Yii::$app->charset : null) ?: mb_internal_encoding(); |
||
39 | } |
||
40 | |||
41 | 4 | public function renderH($title, $prefix) |
|
45 | |||
46 | 3 | public function renderH1($title) |
|
47 | { |
||
48 | 3 | return $this->renderH($title, '#'); |
|
49 | } |
||
50 | |||
51 | 1 | public function renderH2($title) |
|
52 | { |
||
53 | 1 | return $this->renderH($title, '##'); |
|
54 | } |
||
55 | |||
56 | 1 | public function renderText($text) |
|
57 | { |
||
58 | 1 | $text = trim($text); |
|
59 | |||
60 | 1 | return $text ? "\n$text\n" : ''; |
|
61 | } |
||
62 | |||
63 | 1 | public function renderBold($text) |
|
64 | { |
||
65 | 1 | $text = trim($text); |
|
66 | |||
67 | 1 | return $this->renderText('**' . $text . '**'); |
|
68 | } |
||
69 | |||
70 | 2 | public function renderSection($section, $default = null) |
|
71 | { |
||
72 | 2 | $file = 'readme/' . str_replace(' ', '', $section); |
|
73 | 2 | $path = Yii::getAlias("@root/docs/$file.md"); |
|
74 | 2 | $text = file_exists($path) ? file_get_contents($path) : $this->getSection($file, $default); |
|
75 | 2 | $text = trim($text); |
|
76 | |||
77 | 2 | return $text ? "\n## $section\n\n$text\n" : ''; |
|
78 | } |
||
79 | |||
80 | 2 | public function getSection($file, $default = null) |
|
92 | |||
93 | /** |
||
94 | * Set sections list. |
||
95 | * @param array $value |
||
96 | */ |
||
97 | public function setSections($value) |
||
98 | { |
||
99 | $this->_sections = (array) $value; |
||
100 | } |
||
101 | |||
102 | /** |
||
103 | * Returns sections list. Returns default list if not set. |
||
104 | * @return array |
||
105 | */ |
||
106 | 2 | public function getSections() |
|
107 | { |
||
108 | 2 | if (empty($this->_sections)) { |
|
109 | 2 | $this->_sections = ['Requirements', 'Installation', 'Idea', 'Configuration', 'Basic Usage', 'Usage', 'Support', 'License', 'Acknowledgements', 'Acknowledgments']; |
|
110 | } |
||
111 | |||
112 | 2 | return $this->_sections; |
|
113 | } |
||
114 | |||
115 | /** |
||
116 | * Render all configured sections. |
||
117 | * @return string |
||
118 | */ |
||
119 | 2 | public function renderSections($sections = null) |
|
131 | |||
132 | /** |
||
133 | * Render all configured badges. |
||
134 | * @return string |
||
135 | */ |
||
136 | 2 | public function renderBadges() |
|
137 | { |
||
138 | 2 | $badges = $this->badges; |
|
|
|||
139 | 2 | if (!$badges) { |
|
140 | return ''; |
||
141 | } |
||
142 | 2 | $pm = $this->takeGoal('package')->getPackageManager(); |
|
143 | 2 | if (!$pm || !$pm->getConfiguration()->getRequire()) { |
|
144 | 2 | unset($badges['versioneye.dependencies']); |
|
145 | } |
||
146 | 2 | $res = ''; |
|
147 | 2 | foreach ($badges as $badge => $tpl) { |
|
148 | 2 | if (!$tpl) { |
|
149 | 2 | $tpl = $this->markdownBadges[$badge]; |
|
150 | } |
||
151 | 2 | if ($tpl === 'disabled') { |
|
152 | continue; |
||
153 | } |
||
154 | 2 | $res .= $this->renderBadge($tpl) . "\n"; |
|
155 | } |
||
156 | |||
157 | 2 | return $res ? "\n$res" : ''; |
|
158 | } |
||
159 | |||
160 | /** |
||
161 | * Render badge by given template. |
||
162 | * @param string $template string to render |
||
163 | * @return string |
||
164 | */ |
||
165 | 2 | public function renderBadge($template) |
|
169 | |||
170 | /** |
||
171 | * Twig getter. |
||
172 | * @return \Twig_Environment |
||
173 | */ |
||
174 | 2 | public function getTwig() |
|
182 | } |
||
183 |
Since your code implements the magic setter
_set
, this function will be called for any write access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.Since the property has write access only, you can use the @property-write annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.