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