1
|
|
|
<?php |
2
|
|
|
// phpcs:ignoreFile |
3
|
|
|
/** |
4
|
|
|
* Summary of the File DocBlock. |
5
|
|
|
* |
6
|
|
|
* Description of the File. |
7
|
|
|
* |
8
|
|
|
* @package Luigi\Pizza |
9
|
|
|
* @author Mike van Riel <[email protected]> |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Luigi\Pizza |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* The high VAT percentage. |
16
|
|
|
* |
17
|
|
|
* This describes the VAT percentage for all non-food items. |
18
|
|
|
* |
19
|
|
|
* @var integer |
20
|
|
|
*/ |
21
|
|
|
const VAT_HIGH = 21; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* The low VAT percentage. |
25
|
|
|
* |
26
|
|
|
* This describes the VAT percentage for all non-food items. |
27
|
|
|
* |
28
|
|
|
* @var integer |
29
|
|
|
*/ |
30
|
|
|
define('Luigi\Pizza\VAT_LOW', 6); |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var integer SIZE_5CM A 5 centimeter pizza size. |
34
|
|
|
* @var integer SIZE_10CM A 10 centimeter pizza size. |
35
|
|
|
* @var integer SIZE_15CM A 15 centimeter pizza size. |
36
|
|
|
* @var integer SIZE_20CM A 20 centimeter pizza size. |
37
|
|
|
* @var integer DEFAULT_SIZE The default Pizza size if you don't provide your own. |
38
|
|
|
*/ |
39
|
|
|
const SIZE_5CM = 5, SIZE_10CM = 10, SIZE_15CM = 15, SIZE_20CM = 20, DEFAULT_SIZE = SIZE_20CM; |
40
|
|
|
|
41
|
|
|
trait ExampleNestedTrait |
42
|
|
|
{ |
43
|
|
|
private function exampleTraitMethod() |
44
|
|
|
{ |
45
|
|
|
} |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* A single item with a value |
50
|
|
|
* |
51
|
|
|
* Represents something with a price. |
52
|
|
|
*/ |
53
|
|
|
trait HasPrice |
54
|
|
|
{ |
55
|
|
|
use ExampleNestedTrait; |
56
|
|
|
|
57
|
|
|
private $temporaryPrice = 1; |
58
|
|
|
|
59
|
|
|
public function getPrice() |
60
|
|
|
{ |
61
|
|
|
return $this->price; |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Any class implementing this interface has an associated price. |
67
|
|
|
* |
68
|
|
|
* Using this interface we can easily add the price of all components in a pizza by checking for this interface and |
69
|
|
|
* adding the prices together for all components. |
70
|
|
|
*/ |
71
|
|
|
interface Valued |
72
|
|
|
{ |
73
|
|
|
const BASE_PRICE = 1; |
74
|
|
|
|
75
|
|
|
function getPrice(); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
interface Series |
79
|
|
|
{ |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
interface Style extends Valued |
83
|
|
|
{ |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
interface Sauce extends Valued |
87
|
|
|
{ |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
interface Topping extends Valued, \Serializable |
91
|
|
|
{ |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
abstract class PizzaComponentFactory implements \Traversable, Valued |
95
|
|
|
{ |
96
|
|
|
public function add() |
97
|
|
|
{ |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* Calculates the price for this specific component. |
102
|
|
|
* |
103
|
|
|
* @param float[] $...additionalPrices Additional costs may be passed |
104
|
|
|
* |
105
|
|
|
* @return float |
106
|
|
|
*/ |
107
|
|
|
abstract protected function calculatePrice(); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
final class StyleFactory extends PizzaComponentFactory |
111
|
|
|
{ |
112
|
|
|
public function getPrice() |
113
|
|
|
{ |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
protected function calculatePrice() |
117
|
|
|
{ |
118
|
|
|
} |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
final class SauceFactory extends PizzaComponentFactory |
122
|
|
|
{ |
123
|
|
|
public function getPrice() |
124
|
|
|
{ |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
protected function calculatePrice() |
128
|
|
|
{ |
129
|
|
|
} |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
final class ToppingFactory extends PizzaComponentFactory |
133
|
|
|
{ |
134
|
|
|
public function getPrice() |
135
|
|
|
{ |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
protected function calculatePrice() |
139
|
|
|
{ |
140
|
|
|
} |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
final class ItalianStyle implements Style |
144
|
|
|
{ |
145
|
|
|
use HasPrice; |
146
|
|
|
|
147
|
|
|
private $price = 2.0; |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
final class AmericanStyle implements Style |
151
|
|
|
{ |
152
|
|
|
use HasPrice; |
153
|
|
|
|
154
|
|
|
private $price = 1.5; |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
final class TomatoSauce implements Sauce |
158
|
|
|
{ |
159
|
|
|
use HasPrice; |
160
|
|
|
|
161
|
|
|
private $price = 1.5; |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
final class CheeseTopping implements Topping |
165
|
|
|
{ |
166
|
|
|
use HasPrice; |
167
|
|
|
|
168
|
|
|
private $price = 1.5; |
169
|
|
|
|
170
|
|
|
public function serialize() |
171
|
|
|
{ |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
public function unserialize($serialized) |
175
|
|
|
{ |
176
|
|
|
} |
177
|
|
|
} |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
namespace Luigi |
181
|
|
|
{ |
182
|
|
|
/** |
183
|
|
|
* Class representing a single Pizza. |
184
|
|
|
* |
185
|
|
|
* This is Luigi's famous Pizza. |
186
|
|
|
* |
187
|
|
|
* @package Luigi\Pizza |
188
|
|
|
*/ |
189
|
|
|
class Pizza implements Pizza\Valued |
190
|
|
|
{ |
191
|
|
|
/** |
192
|
|
|
* The packaging method used to transport the pizza. |
193
|
|
|
*/ |
194
|
|
|
const PACKAGING = 'box'; |
195
|
|
|
|
196
|
|
|
const |
197
|
|
|
/** @var string DELIVERY designates that the delivery method is to deliver the pizza to the customer. */ |
198
|
|
|
DELIVERY = 'delivery', |
199
|
|
|
/** @var string PICKUP designates that the delivery method is that the customer picks the pizza up. */ |
200
|
|
|
PICKUP = 'pickup'; |
201
|
|
|
|
202
|
|
|
/** @var static contains the active instance for this Pizza. */ |
203
|
|
|
static private $instance; |
204
|
|
|
|
205
|
|
|
/** |
206
|
|
|
* @var Pizza\Style $style |
207
|
|
|
* @var Pizza\Sauce|null $sauce |
208
|
|
|
* @var Pizza\Topping[] $toppings |
209
|
|
|
*/ |
210
|
|
|
private $style, $sauce, $toppings; |
211
|
|
|
|
212
|
|
|
/** |
213
|
|
|
* The size of the pizza in centimeters, defaults to 20cm. |
214
|
|
|
* |
215
|
|
|
* @var int |
216
|
|
|
*/ |
217
|
|
|
public $size = \Luigi\Pizza\SIZE_20CM; |
218
|
|
|
|
219
|
|
|
var $legacy; // don't use this anymore! |
220
|
|
|
|
221
|
|
|
protected |
222
|
|
|
/** @var string $packaging The type of packaging for this Pizza */ |
223
|
|
|
$packaging = self::PACKAGING, |
224
|
|
|
/** @var string $deliveryMethod Is the customer picking this pizza up or must it be delivered? */ |
225
|
|
|
$deliveryMethod; |
226
|
|
|
|
227
|
|
|
private function __construct(Pizza\Style $style) |
228
|
|
|
{ |
229
|
|
|
$this->style = $style; |
230
|
|
|
} |
231
|
|
|
|
232
|
|
|
/** |
233
|
|
|
* Creates a new instance of a Pizza. |
234
|
|
|
* |
235
|
|
|
* This method can be used to instantiate a new object of this class which can then be retrieved using |
236
|
|
|
* {@see self::getInstance()}. |
237
|
|
|
* |
238
|
|
|
* @param Pizza\Style $style |
239
|
|
|
* |
240
|
|
|
* @see self::getInstance to retrieve the pizza object. |
241
|
|
|
* |
242
|
|
|
* @return void |
243
|
|
|
*/ |
244
|
|
|
public static function createInstance(Pizza\Style $style) |
245
|
|
|
{ |
246
|
|
|
self::$instance = new static($style); |
247
|
|
|
} |
248
|
|
|
|
249
|
|
|
/** |
250
|
|
|
* @return self |
251
|
|
|
*/ |
252
|
|
|
static function getInstance() |
253
|
|
|
{ |
254
|
|
|
return self::$instance; |
255
|
|
|
} |
256
|
|
|
|
257
|
|
|
final public function setSauce(Pizza\Sauce $sauce) |
258
|
|
|
{ |
259
|
|
|
$this->sauce = $sauce; |
260
|
|
|
} |
261
|
|
|
|
262
|
|
|
final public function addTopping(Pizza\Topping $topping) |
263
|
|
|
{ |
264
|
|
|
$this->toppings[] = $topping; |
265
|
|
|
} |
266
|
|
|
|
267
|
|
|
public function setSize(&$size = \Luigi\Pizza\SIZE_20CM) |
268
|
|
|
{ |
269
|
|
|
} |
270
|
|
|
|
271
|
|
|
public function getPrice() |
272
|
|
|
{ |
273
|
|
|
} |
274
|
|
|
} |
275
|
|
|
} |
276
|
|
|
|