<?php
abstract
class
PizzaStore {
public
function
orderPizza(
$type
) {
$pizza
=
$this
->createPizza(
$type
);
$pizza
->prepare();
$pizza
->bake();
$pizza
->cut();
$pizza
->box();
return
$pizza
;
}
public
abstract
function
createPizza(
$type
);
}
class
NYPizzaStore
extends
PizzaStore {
public
function
createPizza(
$type
) {
if
(
$type
==
"cheese"
) {
return
new
NYStyleCheesePizza();
}
elseif
(
$type
==
"veggie"
) {
return
new
NYStyleVeggiePizza();
}
elseif
(
$type
==
"clam"
) {
return
new
NYStyleClamPizza();
}
elseif
(
$type
==
"papperoni"
) {
return
new
NYStylePapperoniPizza();
}
else
{
return
null;
}
}
}
class
ChicagoPizzaStore
extends
PizzaStore {
public
function
createPizza(
$type
) {
if
(
$type
==
"cheese"
) {
return
new
ChicagoStyleCheesePizza();
}
elseif
(
$type
==
"veggie"
) {
return
new
ChicagoStyleVeggiePizza();
}
elseif
(
$type
==
"clam"
) {
return
new
ChicagoStyleClamPizza();
}
elseif
(
$type
==
"papperoni"
) {
return
new
ChicagoStylePapperoniPizza();
}
else
{
return
null;
}
}
}
abstract
class
Pizza {
public
$name
;
public
$dough
;
public
$sauce
;
public
$toppings
=
array
();
public
function
prepare() {
echo
"Preparing "
.
$this
->name .
"n"
;
echo
"Yossing dough...n"
;
echo
"Adding sauce...n"
;
echo
"Adding toppings: n"
;
for
(
$i
= 0;
$i
<
count
(
$this
->toppings);
$i
++) {
echo
" "
.
$this
->toppings[
$i
] .
"n"
;
}
}
public
function
bake() {
echo
"Bake for 25 minutes at 350n"
;
}
public
function
cut() {
echo
"Cutting the pizza into diagonal slicesn"
;
}
public
function
box() {
echo
"Place pizza in official PizzaStore boxn"
;
}
public
function
getName() {
return
$this
->name;
}
}
class
NYStyleCheesePizza
extends
Pizza {
public
function
__construct() {
$this
->name =
"NY Style Sauce and cheese Pizza"
;
$this
->dough =
"Thin Crust Dough"
;
$this
->sauce =
"Marinara Sauce"
;
$this
->toppings[] =
"Grated Reggiano Cheese"
;
}
}
class
NYStyleVeggiePizza
extends
Pizza {
public
function
__construct() {
$this
->name =
"NY Style Sauce and veggie Pizza"
;
$this
->dough =
"Thin Crust Dough"
;
$this
->sauce =
"Marinara Sauce"
;
$this
->toppings[] =
"Grated Reggiano veggie"
;
}
}
class
NYStyleClamPizza
extends
Pizza {
public
function
__construct() {
$this
->name =
"NY Style Sauce and clam Pizza"
;
$this
->dough =
"Thin Crust Dough"
;
$this
->sauce =
"Marinara Sauce"
;
$this
->toppings[] =
"Grated Reggiano clam"
;
}
}
class
NYStylePapperoniPizza
extends
Pizza {
public
function
__construct() {
$this
->name =
"NY Style Sauce and papperoni Pizza"
;
$this
->dough =
"Thin Crust Dough"
;
$this
->sauce =
"Marinara Sauce"
;
$this
->toppings[] =
"Grated Reggiano papperoni"
;
}
}
class
ChicagoStyleCheesePizza
extends
Pizza {
public
function
__construct() {
$this
->name =
"Chicago Style Deep Dish Cheese Pizza"
;
$this
->dough =
"Extra Thick Crust Dough"
;
$this
->sauce =
"Plum Tomato Sauce"
;
$this
->toppings[] =
"Shredded Mozzarella Cheese"
;
}
public
function
cut() {
echo
"Cutting the pizza into square slicesn"
;
}
}
$myStore
=
new
NYPizzaStore();
$chicagoStore
=
new
ChicagoPizzaStore();
$pizza
=
$myStore
->orderPizza(
"cheese"
);
echo
"Ethan ordered a "
.
$pizza
->getName() .
"n"
;
$pizza
=
$chicagoStore
->orderPizza(
"cheese"
);
echo
"Ethan ordered a "
.
$pizza
->getName() .
"n"
;
?>