1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SixtyNine\Cloud\Factory; |
4
|
|
|
|
5
|
|
|
|
6
|
|
|
use SixtyNine\Cloud\Placer\CircularPlacer; |
7
|
|
|
use SixtyNine\Cloud\Placer\LinearHorizontalPlacer; |
8
|
|
|
use SixtyNine\Cloud\Placer\LinearVerticalPlacer; |
9
|
|
|
use SixtyNine\Cloud\Placer\LissajouPlacer; |
10
|
|
|
use SixtyNine\Cloud\Placer\PlacerInterface; |
11
|
|
|
use SixtyNine\Cloud\Placer\SpiranglePlacer; |
12
|
|
|
use SixtyNine\Cloud\Placer\WordlePlacer; |
13
|
|
|
use Webmozart\Assert\Assert; |
14
|
|
|
|
15
|
|
|
class PlacerFactory |
16
|
|
|
{ |
17
|
|
|
const PLACER_CIRCULAR = 'circular'; |
18
|
|
|
const PLACER_WORDLE = 'wordle'; |
19
|
|
|
const PLACER_SPIRANGLE = 'spirangle'; |
20
|
|
|
const PLACER_LINEAR_H = 'linear-h'; |
21
|
|
|
const PLACER_LINEAR_V = 'linear-v'; |
22
|
|
|
const PLACER_LISSAJOU = 'lissajou'; |
23
|
|
|
|
24
|
|
|
/** @var PlacerFactory */ |
25
|
|
|
protected static $instance; |
26
|
|
|
|
27
|
|
|
/** @var array */ |
28
|
|
|
protected $placers = array( |
29
|
|
|
self::PLACER_CIRCULAR => CircularPlacer::class, |
30
|
|
|
self::PLACER_WORDLE => WordlePlacer::class, |
31
|
|
|
self::PLACER_SPIRANGLE => SpiranglePlacer::class, |
32
|
|
|
self::PLACER_LINEAR_H => LinearHorizontalPlacer::class, |
33
|
|
|
self::PLACER_LINEAR_V => LinearVerticalPlacer::class, |
34
|
|
|
self::PLACER_LISSAJOU => LissajouPlacer::class, |
35
|
|
|
); |
36
|
|
|
|
37
|
|
|
protected function __construct() { } |
38
|
|
|
|
39
|
5 |
|
public static function getInstance() |
40
|
|
|
{ |
41
|
5 |
|
if (!self::$instance) { |
42
|
1 |
|
self::$instance = new self(); |
43
|
|
|
} |
44
|
5 |
|
return self::$instance; |
45
|
|
|
} |
46
|
|
|
|
47
|
1 |
|
public function getPlacersNames() |
48
|
|
|
{ |
49
|
1 |
|
return array_keys($this->placers); |
50
|
|
|
} |
51
|
|
|
|
52
|
2 |
|
public function getDefaultPlacer($imgWidth, $imgHeight) |
53
|
|
|
{ |
54
|
2 |
|
return $this->getPlacer(self::PLACER_CIRCULAR, $imgWidth, $imgHeight); |
55
|
|
|
} |
56
|
|
|
|
57
|
5 |
|
public function getPlacer($name, $imgWidth, $imgHeight, $increment = 10) |
58
|
|
|
{ |
59
|
5 |
|
$className = $this->getPlacerClass($name); |
60
|
5 |
|
return new $className($imgWidth, $imgHeight, $increment); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @param string $name |
65
|
|
|
* @return PlacerInterface |
66
|
|
|
* @throws \InvalidArgumentException |
67
|
|
|
*/ |
68
|
5 |
|
protected function getPlacerClass($name) |
69
|
|
|
{ |
70
|
5 |
|
Assert::keyExists($this->placers, $name, 'Placer not found: ' . $name); |
71
|
5 |
|
return $this->placers[$name]; |
72
|
|
|
} |
73
|
|
|
} |