27
27
use Phing \Io \FileWriter ;
28
28
use Phing \Io \File ;
29
29
use Phing \Project ;
30
+ use Phing \Util \StringHelper ;
30
31
use Psr \Http \Message \ResponseInterface ;
31
32
use SimpleXMLElement ;
32
33
use XSLTProcessor ;
@@ -113,9 +114,9 @@ public function init(): void
113
114
$ this ->log ($ exceptionMessage , Project::MSG_ERR );
114
115
throw new BuildException ($ exceptionMessage );
115
116
}
116
- $ this ->setFormat (VisualizerTask ::FORMAT_PNG );
117
- $ this ->setServer (VisualizerTask ::SERVER );
118
- $ this ->setDirection (VisualizerTask ::ARROWS_VERTICAL );
117
+ $ this ->setFormat (self ::FORMAT_PNG );
118
+ $ this ->setServer (self ::SERVER );
119
+ $ this ->setDirection (self ::ARROWS_VERTICAL );
119
120
$ this ->setShowTitle (true );
120
121
$ this ->setShowDescription (false );
121
122
$ this ->setFooter ('' );
@@ -140,6 +141,7 @@ public function main(): void
140
141
* Retrieves loaded buildfiles and generates a PlantUML diagram
141
142
*
142
143
* @return string
144
+ * @throws \Phing\Io\IOException
143
145
*/
144
146
protected function generatePumlDiagram (): string
145
147
{
@@ -158,6 +160,7 @@ protected function generatePumlDiagram(): string
158
160
* @param \Phing\Io\File[] $buildFiles
159
161
*
160
162
* @return string
163
+ * @throws \Phing\Io\IOException
161
164
*/
162
165
protected function generatePuml (array $ buildFiles ): string
163
166
{
@@ -167,17 +170,17 @@ protected function generatePuml(array $buildFiles): string
167
170
throw new BuildException ($ exceptionMessage );
168
171
}
169
172
170
- $ puml = $ this ->transformToPuml ($ firstBuildFile , VisualizerTask ::XSL_HEADER );
173
+ $ puml = $ this ->transformToPuml ($ firstBuildFile , self ::XSL_HEADER );
171
174
172
175
$ puml = array_reduce ($ buildFiles , function (string $ carry , File $ buildFile ) {
173
- return $ carry . $ this ->transformToPuml ($ buildFile , VisualizerTask ::XSL_CALLS );
176
+ return $ carry . $ this ->transformToPuml ($ buildFile , self ::XSL_CALLS );
174
177
}, $ puml );
175
178
176
179
$ puml = array_reduce ($ buildFiles , function (string $ carry , File $ buildFile ) {
177
- return $ carry . $ this ->transformToPuml ($ buildFile , VisualizerTask ::XSL_TARGETS );
180
+ return $ carry . $ this ->transformToPuml ($ buildFile , self ::XSL_TARGETS );
178
181
}, $ puml );
179
182
180
- $ puml .= $ this ->transformToPuml ($ firstBuildFile , VisualizerTask ::XSL_FOOTER );
183
+ $ puml .= $ this ->transformToPuml ($ firstBuildFile , self ::XSL_FOOTER );
181
184
182
185
return $ puml ;
183
186
}
@@ -263,10 +266,10 @@ public function getFormat(): string
263
266
public function setFormat (string $ format ): VisualizerTask
264
267
{
265
268
switch ($ format ) {
266
- case VisualizerTask ::FORMAT_PUML :
267
- case VisualizerTask ::FORMAT_PNG :
268
- case VisualizerTask ::FORMAT_EPS :
269
- case VisualizerTask ::FORMAT_SVG :
269
+ case self ::FORMAT_PUML :
270
+ case self ::FORMAT_PNG :
271
+ case self ::FORMAT_EPS :
272
+ case self ::FORMAT_SVG :
270
273
$ this ->format = $ format ;
271
274
break ;
272
275
default :
@@ -301,9 +304,9 @@ public function setDestination(?string $destination): self
301
304
/**
302
305
* Figure diagram's file path
303
306
*
304
- * @param string $buildfilePath Path to main buildfile
305
- * @param string $format Extension to use
306
- * @param null|string $destination Desired destination provided by user
307
+ * @param string $buildfilePath Path to main buildfile, this is used as fallback dir.
308
+ * @param string $format Extension to use.
309
+ * @param null|string $destination Desired destination provided by user.
307
310
*
308
311
* @return string
309
312
*/
@@ -321,7 +324,12 @@ protected function resolveDestination(string $buildfilePath, string $format, ?st
321
324
$ destination .= DIRECTORY_SEPARATOR . $ buildfileInfo ['filename ' ] . '. ' . $ format ;
322
325
}
323
326
324
- // Check if path is available
327
+ // Adding right extension if necessary
328
+ if (!StringHelper::endsWith (". $ format " , $ destination )) {
329
+ $ destination .= ". $ format " ;
330
+ }
331
+
332
+ // Parent directory must exist
325
333
if (!is_dir (dirname ($ destination ))) {
326
334
$ exceptionMessage = "Directory ' $ destination' is invalid " ;
327
335
$ this ->log ($ exceptionMessage , Project::MSG_ERR );
@@ -342,7 +350,7 @@ protected function resolveDestination(string $buildfilePath, string $format, ?st
342
350
*/
343
351
protected function generateImage (string $ pumlDiagram , string $ format ): string
344
352
{
345
- if ($ format === VisualizerTask ::FORMAT_PUML ) {
353
+ if ($ format === self ::FORMAT_PUML ) {
346
354
$ this ->log ('Bypassing, no need to call server ' , Project::MSG_DEBUG );
347
355
348
356
return $ pumlDiagram ;
@@ -360,6 +368,7 @@ protected function generateImage(string $pumlDiagram, string $format): string
360
368
*
361
369
* @param string $pumlDiagram
362
370
* @param string $format
371
+ * @throws \Jawira\PlantUmlClient\ClientException
363
372
*/
364
373
protected function prepareImageUrl (string $ pumlDiagram , string $ format ): void
365
374
{
@@ -466,7 +475,7 @@ protected function processResponse(ResponseInterface $response): void
466
475
$ this ->log ("Response status: $ status " , Project::MSG_DEBUG );
467
476
$ this ->log ("Response reason: $ reasonPhrase " , Project::MSG_DEBUG );
468
477
469
- if ($ status !== VisualizerTask ::STATUS_OK ) {
478
+ if ($ status !== self ::STATUS_OK ) {
470
479
$ exceptionMessage = "Request unsuccessful. Response from server: $ status $ reasonPhrase " ;
471
480
$ this ->log ($ exceptionMessage , Project::MSG_ERR );
472
481
throw new BuildException ($ exceptionMessage );
@@ -484,7 +493,7 @@ protected function processResponse(ResponseInterface $response): void
484
493
protected function saveToFile (string $ content , File $ destination ): void
485
494
{
486
495
$ path = $ destination ->getPath ();
487
- $ this ->log ("Writing: $ path " , Project:: MSG_INFO );
496
+ $ this ->log ("Writing: $ path " );
488
497
489
498
(new FileWriter ($ destination ))->write ($ content );
490
499
}
0 commit comments