|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Sandro Keil (https://sandro-keil.de) |
|
4
|
|
|
* |
|
5
|
|
|
* @link http://github.com/sandrokeil/interop-config for the canonical source repository |
|
6
|
|
|
* @copyright Copyright (c) 2015-2016 Sandro Keil |
|
7
|
|
|
* @license http://github.com/sandrokeil/interop-config/blob/master/LICENSE.md New BSD License |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
namespace InteropTest\Config\TestAsset; |
|
11
|
|
|
|
|
12
|
|
|
use Interop\Config\ConfigurationTrait; |
|
13
|
|
|
use Interop\Config\ProvidesDefaultOptions; |
|
14
|
|
|
use Interop\Config\RequiresConfigId; |
|
15
|
|
|
use Interop\Config\RequiresMandatoryOptions; |
|
16
|
|
|
|
|
17
|
|
|
class UniversalContainerIdConfiguration implements RequiresConfigId, ProvidesDefaultOptions, RequiresMandatoryOptions |
|
18
|
|
|
{ |
|
19
|
|
|
use ConfigurationTrait; |
|
20
|
|
|
|
|
21
|
|
|
const TYPE_ARRAY_ITERATOR = 0; |
|
22
|
|
|
const TYPE_ARRAY_OBJECT = 1; |
|
23
|
|
|
const TYPE_ARRAY_ARRAY = 2; |
|
24
|
|
|
const TYPE_ONLY_ITERATOR = 3; |
|
25
|
|
|
|
|
26
|
|
|
private static $dimensions = [ |
|
27
|
|
|
'doctrine', |
|
28
|
|
|
'universal', |
|
29
|
|
|
]; |
|
30
|
|
|
|
|
31
|
|
|
private static $mandatoryOptions = [ |
|
32
|
|
|
'params' => ['user', 'dbname'], |
|
33
|
|
|
'driverClass', |
|
34
|
|
|
]; |
|
35
|
|
|
|
|
36
|
|
|
private static $defaultOptions = [ |
|
37
|
|
|
'params' => [ |
|
38
|
|
|
'host' => 'awesomehost', |
|
39
|
|
|
'port' => '4444', |
|
40
|
|
|
], |
|
41
|
|
|
]; |
|
42
|
|
|
|
|
43
|
|
|
private $type; |
|
44
|
|
|
|
|
45
|
|
|
public function __construct(int $type) |
|
46
|
|
|
{ |
|
47
|
|
|
$this->type = $type; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
public function dimensions(): iterable |
|
51
|
|
|
{ |
|
52
|
|
|
return $this->getData('dimensions'); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
public function mandatoryOptions(): iterable |
|
56
|
|
|
{ |
|
57
|
|
|
return $this->getData('mandatoryOptions'); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
public function defaultOptions(): iterable |
|
61
|
|
|
{ |
|
62
|
|
|
return $this->getData('defaultOptions'); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
private function getData($name) |
|
66
|
|
|
{ |
|
67
|
|
|
switch ($this->type) { |
|
68
|
|
|
case self::TYPE_ARRAY_ITERATOR: |
|
69
|
|
|
return new \ArrayIterator(self::$$name); |
|
70
|
|
|
break; |
|
|
|
|
|
|
71
|
|
|
case self::TYPE_ARRAY_OBJECT: |
|
72
|
|
|
return new \ArrayObject(self::$$name); |
|
73
|
|
|
break; |
|
|
|
|
|
|
74
|
|
|
case self::TYPE_ONLY_ITERATOR: |
|
75
|
|
|
return new OnlyIterator(self::$$name); |
|
76
|
|
|
break; |
|
|
|
|
|
|
77
|
|
|
case self::TYPE_ARRAY_ARRAY: |
|
78
|
|
|
default: |
|
79
|
|
|
return self::$$name; |
|
80
|
|
|
break; |
|
|
|
|
|
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
|
The break statement is not necessary if it is preceded for example by a return statement:
If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.