|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This software package is licensed under AGPL or Commercial license. |
|
5
|
|
|
* |
|
6
|
|
|
* @package maslosoft/mangan |
|
7
|
|
|
* @licence AGPL or Commercial |
|
8
|
|
|
* @copyright Copyright (c) Piotr Masełkowski <[email protected]> |
|
9
|
|
|
* @copyright Copyright (c) Maslosoft |
|
10
|
|
|
* @copyright Copyright (c) Others as mentioned in code |
|
11
|
|
|
* @link http://maslosoft.com/mangan/ |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
namespace Maslosoft\Mangan\Options; |
|
15
|
|
|
|
|
16
|
|
|
use Maslosoft\Mangan\Helpers\PropertyMaker; |
|
17
|
|
|
use Maslosoft\Mangan\Mangan; |
|
18
|
|
|
use Maslosoft\Mangan\Meta\DocumentTypeMeta; |
|
19
|
|
|
use Maslosoft\Mangan\Meta\ManganMeta; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* EntityOptions |
|
23
|
|
|
* |
|
24
|
|
|
* @author Piotr Maselkowski <pmaselkowski at gmail.com> |
|
25
|
|
|
*/ |
|
26
|
|
|
class EntityOptions |
|
27
|
|
|
{ |
|
28
|
|
|
|
|
29
|
|
|
use \Maslosoft\Mangan\Traits\Defaults\MongoClientOptions; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* |
|
33
|
|
|
* @var Mangan |
|
34
|
|
|
*/ |
|
35
|
|
|
private $_mangan = null; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Values of this instance |
|
39
|
|
|
* @var mixed[] |
|
40
|
|
|
*/ |
|
41
|
|
|
private $_values = []; |
|
42
|
|
|
private $_defaults = []; |
|
43
|
|
|
|
|
44
|
92 |
|
public function __construct($model) |
|
45
|
|
|
{ |
|
46
|
|
|
// This is to use get/set |
|
47
|
92 |
|
foreach ($this->_getOptionNames() as $name) |
|
48
|
|
|
{ |
|
49
|
92 |
|
PropertyMaker::defineProperty($this, $name, $this->_defaults); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
92 |
|
foreach (ManganMeta::create($model)->type()->clientFlags as $name => $value) |
|
53
|
|
|
{ |
|
54
|
1 |
|
$this->_values[$name] = $value; |
|
55
|
|
|
} |
|
56
|
92 |
|
$this->_mangan = Mangan::fromModel($model); |
|
57
|
92 |
|
} |
|
58
|
|
|
|
|
59
|
88 |
|
public function __get($name) |
|
60
|
|
|
{ |
|
61
|
88 |
|
if (array_key_exists($name, $this->_values)) |
|
62
|
|
|
{ |
|
63
|
3 |
|
return $this->_values[$name]; // We have flag set, return it |
|
64
|
|
|
} |
|
65
|
86 |
|
return $this->_mangan->$name; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
2 |
|
public function __set($name, $value) |
|
69
|
|
|
{ |
|
70
|
2 |
|
$this->_values[$name] = $value; |
|
71
|
2 |
|
} |
|
72
|
|
|
|
|
73
|
|
|
public function __unset($name) |
|
74
|
|
|
{ |
|
75
|
|
|
unset($this->_values[$name]); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
public function __isset($name) |
|
79
|
|
|
{ |
|
80
|
|
|
return isset($this->_values[$name]); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
85 |
|
public function getSaveOptions($extraOptions = []) |
|
84
|
|
|
{ |
|
85
|
85 |
|
$result = []; |
|
86
|
85 |
|
foreach ($this->_getOptionNames() as $name) |
|
87
|
|
|
{ |
|
88
|
85 |
|
$result[$name] = $this->$name; |
|
89
|
|
|
} |
|
90
|
85 |
|
foreach ($extraOptions as $name => $value) |
|
91
|
|
|
{ |
|
92
|
60 |
|
$result[$name] = $value; |
|
93
|
|
|
} |
|
94
|
85 |
|
return $result; |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
} |
|
98
|
|
|
|