|
1
|
|
|
<?php |
|
2
|
|
|
namespace Mathielen\ImportEngine\ValueObject; |
|
3
|
|
|
|
|
4
|
|
|
class StorageSelection |
|
5
|
|
|
{ |
|
6
|
|
|
|
|
7
|
|
|
protected $providerId = 'defaultProvider'; |
|
8
|
|
|
protected $id; |
|
9
|
|
|
protected $name; |
|
10
|
|
|
protected $impl; |
|
11
|
|
|
protected $metadata = array(); |
|
12
|
|
|
|
|
13
|
18 |
|
public function __construct($impl, $id=null, $name=null, array $metadata=array()) |
|
14
|
|
|
{ |
|
15
|
18 |
|
$this->impl = $impl; |
|
16
|
18 |
|
$this->id = $id; |
|
17
|
18 |
|
$this->name = $name; |
|
18
|
18 |
|
$this->metadata = $metadata; |
|
19
|
18 |
|
} |
|
20
|
|
|
|
|
21
|
|
|
public function addMetadata($key, $value) |
|
22
|
|
|
{ |
|
23
|
|
|
$this->metadata[$key] = $value; |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
public function setMetadata(array $metadata) |
|
27
|
|
|
{ |
|
28
|
|
|
$this->metadata = $metadata; |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
2 |
|
public function getMetadata($key) |
|
32
|
|
|
{ |
|
33
|
2 |
|
if (!isset($this->metadata[$key])) { |
|
34
|
2 |
|
return null; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
return $this->metadata[$key]; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @return StorageSelection |
|
42
|
|
|
*/ |
|
43
|
1 |
|
public function setProviderId($providerId) |
|
44
|
|
|
{ |
|
45
|
1 |
|
$this->providerId = $providerId; |
|
46
|
|
|
|
|
47
|
1 |
|
return $this; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
1 |
|
public function getProviderId() |
|
51
|
|
|
{ |
|
52
|
1 |
|
return $this->providerId; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
20 |
|
public function getId() |
|
56
|
|
|
{ |
|
57
|
20 |
|
return $this->id; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
1 |
|
public function getName() |
|
61
|
|
|
{ |
|
62
|
1 |
|
return $this->name; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
5 |
|
public function getImpl() |
|
66
|
|
|
{ |
|
67
|
|
|
//TODO some sort of serializable wrapper? |
|
68
|
5 |
|
if (is_array($this->impl) && isset($this->impl['class'])) { |
|
69
|
|
|
$reflectionClass = new \ReflectionClass($this->impl['class']); |
|
70
|
|
|
|
|
71
|
|
|
return $reflectionClass->newInstanceArgs(isset($this->impl['args'])?$this->impl['args']:null); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
5 |
|
return $this->impl; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
public function prePersist() |
|
78
|
|
|
{ |
|
79
|
|
|
if ($this->impl instanceof \SplFileInfo) { |
|
80
|
|
|
|
|
81
|
|
|
//TODO some sort of serializable wrapper? |
|
82
|
|
|
$this->impl = array( |
|
83
|
|
|
'class'=>get_class($this->impl), |
|
84
|
|
|
'args'=>array($this->impl->getRealPath()) |
|
85
|
|
|
); |
|
86
|
|
|
} |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
public function toArray() |
|
90
|
|
|
{ |
|
91
|
|
|
return get_object_vars($this); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
public function __toString() |
|
95
|
|
|
{ |
|
96
|
|
|
return http_build_query ($this->toArray()); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
} |
|
100
|
|
|
|