1 | <?php |
||
12 | class Drawer |
||
13 | { |
||
14 | const BORDER_X = '║'; |
||
15 | |||
16 | const BORDER_Y = '═'; |
||
17 | |||
18 | const BORDER_NW = '╔'; |
||
19 | |||
20 | const BORDER_NE = '╗'; |
||
21 | |||
22 | const BORDER_SE = '╝'; |
||
23 | |||
24 | const BORDER_SW = '╚'; |
||
25 | |||
26 | const NOCK = '║'; |
||
27 | |||
28 | const PILE = '∇'; |
||
29 | |||
30 | const CROSSROADS = '╬'; |
||
31 | |||
32 | const CROSSROADS_UP = '╩'; |
||
33 | |||
34 | const CROSSROADS_DOWN = '╦'; |
||
35 | |||
36 | /** |
||
37 | * @author Andrea Marco Sartori |
||
38 | * |
||
39 | * @var Cerbero\Workflow\Repositories\PipelineRepositoryInterface $pipelines Pipeline repository. |
||
40 | */ |
||
41 | protected $pipelines; |
||
42 | |||
43 | /** |
||
44 | * @author Andrea Marco Sartori |
||
45 | * |
||
46 | * @var Cerbero\Workflow\Console\Drawing\Geometry $geometry The applied geometry. |
||
47 | */ |
||
48 | protected $geometry; |
||
49 | |||
50 | /** |
||
51 | * @author Andrea Marco Sartori |
||
52 | * |
||
53 | * @var array $pipes List of pipes. |
||
54 | */ |
||
55 | protected $pipes; |
||
56 | |||
57 | /** |
||
58 | * @author Andrea Marco Sartori |
||
59 | * |
||
60 | * @var string $drawing The resulting drawing. |
||
61 | */ |
||
62 | protected $drawing = ''; |
||
63 | |||
64 | /** |
||
65 | * Set the dependencies. |
||
66 | * |
||
67 | * @author Andrea Marco Sartori |
||
68 | * |
||
69 | * @param Cerbero\Workflow\Repositories\PipelineRepositoryInterface $pipelines |
||
70 | * @param Cerbero\Workflow\Console\Drawing\Geometry $geometry |
||
71 | * |
||
72 | * @return void |
||
|
|||
73 | */ |
||
74 | 15 | public function __construct(PipelineRepositoryInterface $pipelines, Geometry $geometry) |
|
80 | |||
81 | /** |
||
82 | * Draw the given workflow. |
||
83 | * |
||
84 | * @author Andrea Marco Sartori |
||
85 | * |
||
86 | * @param string $workflow |
||
87 | * |
||
88 | * @return string |
||
89 | */ |
||
90 | 12 | public function draw($workflow) |
|
108 | |||
109 | /** |
||
110 | * Set the pipes of the given workflow. |
||
111 | * |
||
112 | * @author Andrea Marco Sartori |
||
113 | * |
||
114 | * @param string $workflow |
||
115 | * |
||
116 | * @return void |
||
117 | */ |
||
118 | 12 | protected function setPipesOfWorkflow($workflow) |
|
131 | |||
132 | /** |
||
133 | * Draw a character in the middle of the drawing. |
||
134 | * |
||
135 | * @author Andrea Marco Sartori |
||
136 | * |
||
137 | * @param string $character |
||
138 | * |
||
139 | * @return void |
||
140 | */ |
||
141 | 12 | protected function drawCenteredChar($character) |
|
147 | |||
148 | /** |
||
149 | * Draw a row of the drawing. |
||
150 | * |
||
151 | * @author Andrea Marco Sartori |
||
152 | * |
||
153 | * @param string $row |
||
154 | * |
||
155 | * @return void |
||
156 | */ |
||
157 | 12 | protected function drawRow($row) |
|
161 | |||
162 | /** |
||
163 | * Draw the beginning of all pipes. |
||
164 | * |
||
165 | * @author Andrea Marco Sartori |
||
166 | * |
||
167 | * @return void |
||
168 | */ |
||
169 | 12 | protected function drawPipesBeginning() |
|
179 | |||
180 | /** |
||
181 | * Draw content wrapped by borders. |
||
182 | * |
||
183 | * @author Andrea Marco Sartori |
||
184 | * |
||
185 | * @param string $content |
||
186 | * |
||
187 | * @return void |
||
188 | */ |
||
189 | 12 | protected function drawBordered($content) |
|
197 | |||
198 | /** |
||
199 | * Draw the top border. |
||
200 | * |
||
201 | * @author Andrea Marco Sartori |
||
202 | * |
||
203 | * @param bool $isCore |
||
204 | * |
||
205 | * @return void |
||
206 | */ |
||
207 | 12 | protected function drawBorderTop($isCore = false) |
|
215 | |||
216 | /** |
||
217 | * Draw a border with the given bendings. |
||
218 | * |
||
219 | * @author Andrea Marco Sartori |
||
220 | * |
||
221 | * @param string $left |
||
222 | * @param string $middle |
||
223 | * @param string $right |
||
224 | * |
||
225 | * @return void |
||
226 | */ |
||
227 | 12 | protected function drawBorder($left, $middle, $right) |
|
239 | |||
240 | /** |
||
241 | * Replace a character in a given position of a string. |
||
242 | * |
||
243 | * @author Andrea Marco Sartori |
||
244 | * |
||
245 | * @param string $original |
||
246 | * @param string $replacement |
||
247 | * @param int $position |
||
248 | * |
||
249 | * @return void |
||
250 | */ |
||
251 | 12 | private function replaceUtf8(&$original, $replacement, $position) |
|
259 | |||
260 | /** |
||
261 | * Draw the core of the workflow. |
||
262 | * |
||
263 | * @author Andrea Marco Sartori |
||
264 | * |
||
265 | * @return void |
||
266 | */ |
||
267 | 12 | protected function drawCore() |
|
275 | |||
276 | /** |
||
277 | * Draw the bottom border. |
||
278 | * |
||
279 | * @author Andrea Marco Sartori |
||
280 | * |
||
281 | * @param bool $isCore |
||
282 | * |
||
283 | * @return void |
||
284 | */ |
||
285 | 12 | protected function drawBorderBottom($isCore = false) |
|
293 | |||
294 | /** |
||
295 | * Draw the end of all pipes. |
||
296 | * |
||
297 | * @author Andrea Marco Sartori |
||
298 | * |
||
299 | * @return void |
||
300 | */ |
||
301 | 12 | protected function drawPipesEnd() |
|
313 | } |
||
314 |
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.