1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Artack\Color; |
6
|
|
|
|
7
|
|
|
use Artack\Color\Color\HEX; |
8
|
|
|
use Artack\Color\Color\HSV; |
9
|
|
|
use Artack\Color\Color\RGB; |
10
|
|
|
use Artack\Color\Converter\Convertible; |
11
|
|
|
use Artack\Color\Converter\HEXToRGBConverter; |
12
|
|
|
use Artack\Color\Converter\HSVToRGBConverter; |
13
|
|
|
use Artack\Color\Converter\RGBToHEXConverter; |
14
|
|
|
use Artack\Color\Converter\RGBToHSVConverter; |
15
|
|
|
use Artack\Color\Transition\HSVTransition; |
16
|
|
|
use Artack\Color\Transition\RGBTransition; |
17
|
|
|
use Artack\Color\Transition\TransitionInterface; |
18
|
|
|
use Fhaculty\Graph\Graph; |
19
|
|
|
use Fhaculty\Graph\Vertex; |
20
|
|
|
|
21
|
|
|
class Factory |
22
|
|
|
{ |
23
|
|
|
const GRAPH_EDGE_KEY_CONVERTER = 'converter'; |
24
|
|
|
|
25
|
590 |
|
public static function createConverter(): Converter |
26
|
|
|
{ |
27
|
590 |
|
return new Converter(new ConverterGraph(self::getConverterGraph())); |
28
|
|
|
} |
29
|
|
|
|
30
|
7 |
|
public static function createTransition(): Transition |
31
|
|
|
{ |
32
|
7 |
|
return new Transition(self::getTransitions(), self::createConverter()); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @return Convertible[] |
37
|
|
|
*/ |
38
|
590 |
|
private static function getConverters(): array |
39
|
|
|
{ |
40
|
|
|
return [ |
41
|
590 |
|
new RGBToHSVConverter(), |
42
|
590 |
|
new HSVToRGBConverter(), |
43
|
590 |
|
new RGBToHEXConverter(), |
44
|
590 |
|
new HEXToRGBConverter(), |
45
|
|
|
]; |
46
|
|
|
} |
47
|
|
|
|
48
|
590 |
|
private static function getColors(): array |
49
|
|
|
{ |
50
|
|
|
return [ |
51
|
590 |
|
RGB::class, |
52
|
|
|
HSV::class, |
53
|
|
|
HEX::class, |
54
|
|
|
]; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @return TransitionInterface[] |
59
|
|
|
*/ |
60
|
7 |
|
private static function getTransitions(): array |
61
|
|
|
{ |
62
|
|
|
return [ |
63
|
7 |
|
new RGBTransition(), |
64
|
7 |
|
new HSVTransition(), |
65
|
|
|
]; |
66
|
|
|
} |
67
|
|
|
|
68
|
590 |
|
private static function getConverterGraph(): Graph |
69
|
|
|
{ |
70
|
590 |
|
$graph = new Graph(); |
71
|
|
|
|
72
|
|
|
/** @var Vertex[] $vertices */ |
73
|
590 |
|
$vertices = []; |
74
|
|
|
|
75
|
590 |
|
foreach (self::getColors() as $color) { |
76
|
590 |
|
$vertices[$color] = $graph->createVertex($color); |
77
|
|
|
} |
78
|
|
|
|
79
|
590 |
|
foreach (self::getConverters() as $converter) { |
80
|
590 |
|
$vertices[$converter::supportsFrom()]->createEdgeTo($vertices[$converter::supportsTo()])->setAttribute(self::GRAPH_EDGE_KEY_CONVERTER, $converter); |
81
|
|
|
} |
82
|
|
|
|
83
|
590 |
|
return $graph; |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|