/
SubproductParams.php
187 lines (155 loc) · 3.42 KB
/
SubproductParams.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
<?php
class Catalog_Model_SubproductParams
{
protected $_id = null;
protected $_product_id = null;
protected $_name = null;
protected $_order = null;
/**
* @param $options
*/
public function __construct(array $options = null)
{
if (is_array($options))
$this->setOptions($options);
}
/**
* @param $name
* @param $value
* @throws Exception
*/
public function __set($name, $value)
{
$method = 'set' . $name;
if (('mapper' == $name) || !method_exists($this, $method))
throw new Exception('Invalid property (' . $name . ')');
return $this->$method($value);
}
/**
* @param $name
* @throws Exception
*/
public function __get($name)
{
$method = 'get' . $name;
if (('mapper' == $name) || !method_exists($this, $method))
throw new Exception('Invalid property (' . $name . ')');
return $this->$method();
}
/**
* @param $options
* @return $this
*/
public function setOptions(array $options)
{
$methods = get_class_methods($this);
foreach ($options as $key => $value) {
$method = 'set' . ucfirst($key);
if (in_array($method, $methods)) {
$this->$method($value);
}
}
return $this;
}
/**
* @return array|null
*/
public function getOptions()
{
$class = new ReflectionClass($this);
$properties = $class->getProperties(ReflectionProperty::IS_PROTECTED);
if(0 === count($properties))
return null;
$data = array();
foreach ($properties as $property) {
$name = preg_split("~_~", $property->getName());
$normaliseName = implode(array_map("ucwords", $name));
$option = lcfirst($normaliseName);
if ($property->isProtected()) {
$property->setAccessible(TRUE);
$data[$option] = $property->getValue($this);
}
}
return $data;
}
/**
* Set value Id
*
* @return $this
* @param $id
*/
public function setId($id)
{
$this->_id = $id;
return $this;
}
/**
* Get value Id
*
* @return mixed
*/
public function getId()
{
return $this->_id;
}
/**
* Set value ProductId
*
* @return $this
* @param $product_id
*/
public function setProductId($product_id)
{
$this->_product_id = $product_id;
return $this;
}
/**
* Get value ProductId
*
* @return mixed
*/
public function getProductId()
{
return $this->_product_id;
}
/**
* Set value Name
*
* @return $this
* @param $name
*/
public function setName($name)
{
$this->_name = $name;
return $this;
}
/**
* Get value Name
*
* @return mixed
*/
public function getName()
{
return $this->_name;
}
/**
* Set value Order
*
* @return $this
* @param $order
*/
public function setOrder($order)
{
$this->_order = $order;
return $this;
}
/**
* Get value Order
*
* @return mixed
*/
public function getOrder()
{
return $this->_order;
}
}