1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use PhUml\Processors\DotProcessor; |
4
|
|
|
use PhUml\Processors\GraphvizProcessor; |
5
|
|
|
use PhUml\Processors\NeatoProcessor; |
6
|
|
|
use PhUml\Processors\StatisticsProcessor; |
7
|
|
|
|
8
|
|
|
abstract class plProcessor |
9
|
|
|
{ |
10
|
|
|
public const INITIAL_INPUT_TYPE = 'application/phuml-structure'; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* @throws plProcessorNotFoundException |
14
|
|
|
*/ |
15
|
|
|
public static function factory($processor): plProcessor |
16
|
|
|
{ |
17
|
|
|
$processor = ucfirst($processor); |
18
|
|
|
if ($processor === 'Dot') { |
19
|
|
|
return new DotProcessor(); |
20
|
|
|
} |
21
|
|
|
if ($processor === 'Neato') { |
22
|
|
|
return new NeatoProcessor(); |
23
|
|
|
} |
24
|
|
|
if ($processor === 'Graphviz') { |
25
|
|
|
return new GraphvizProcessor(); |
26
|
|
|
} |
27
|
|
|
if ($processor === 'Statistics') { |
28
|
|
|
return new StatisticsProcessor(); |
29
|
|
|
} |
30
|
|
|
$classname = "pl{$processor}Processor"; |
31
|
|
|
if (!class_exists($classname)) { |
32
|
|
|
throw new plProcessorNotFoundException($processor); |
33
|
|
|
} |
34
|
|
|
return new $classname(); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public static function getProcessors(): array |
38
|
|
|
{ |
39
|
|
|
return [ |
40
|
|
|
'Graphviz', |
41
|
|
|
'Neato', |
42
|
|
|
'Dot', |
43
|
|
|
'Statistics', |
44
|
|
|
]; |
45
|
|
|
} |
46
|
|
|
|
47
|
6 |
|
public function writeToDisk(string $input, string $output): void |
48
|
|
|
{ |
49
|
6 |
|
file_put_contents($output, $input); |
50
|
6 |
|
} |
51
|
|
|
|
52
|
12 |
|
public function isCompatibleWith(plProcessor $nextProcessor): bool |
53
|
|
|
{ |
54
|
12 |
|
return $this->getOutputType() === $nextProcessor->getInputType(); |
55
|
|
|
} |
56
|
|
|
|
57
|
30 |
|
public function isInitial(): bool |
58
|
|
|
{ |
59
|
30 |
|
return self::INITIAL_INPUT_TYPE === $this->getInputType(); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
abstract public function name(): string; |
63
|
|
|
|
64
|
|
|
abstract public function getInputType(): string; |
65
|
|
|
|
66
|
|
|
abstract public function getOutputType(): string; |
67
|
|
|
|
68
|
|
|
abstract public function process($input); |
69
|
|
|
} |
70
|
|
|
|