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