Last active
August 29, 2015 14:00
-
-
Save mageekguy/11062796 to your computer and use it in GitHub Desktop.
A client, a barman, an order, and some beer!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class drink | |
{ | |
private $alcool = ''; | |
private $pourcent = 0; | |
public function __construct($alcool, $pourcent) | |
{ | |
$this | |
->setAlcool($alcool) | |
->setPourcent($pourcent) | |
; | |
} | |
public function __toString() | |
{ | |
return $this->alcool . ': ' . $this->pourcent . '%'; | |
} | |
public function setPourcent($pourcent) | |
{ | |
$this->pourcent = $pourcent; | |
return $this; | |
} | |
public function setAlcool($alcool) | |
{ | |
$this->alcool = $alcool; | |
return $this; | |
} | |
} | |
class drinks implements iteratorAggregate | |
{ | |
private $drinks = array(); | |
public function destroy() | |
{ | |
$this->drinks = array(); | |
} | |
public function add(drink $drink) | |
{ | |
$this->drinks[] = $drink; | |
return $this; | |
} | |
public function getIterator() | |
{ | |
return new arrayIterator($this->drinks); | |
} | |
} | |
class order | |
{ | |
private $numberOfDrinks = 0; | |
private $alcool = ''; | |
public function setNumberOfDrinks($numberOfDrinks) | |
{ | |
$this->numberOfDrinks = $numberOfDrinks; | |
return $this; | |
} | |
public function getNumberOfDrinks() | |
{ | |
return $this->numberOfDrinks; | |
} | |
public function setAlcool($alcool) | |
{ | |
$this->alcool = $alcool; | |
return $this; | |
} | |
public function getAlcool() | |
{ | |
return $this->alcool; | |
} | |
} | |
class client | |
{ | |
private $drinks = array(); | |
private $creditCardNumber = ''; | |
private $order = null; | |
public function __construct() | |
{ | |
$this->creditCardNumber = uniqid(); | |
$this->order = new order(); | |
} | |
public function order($numberOfDrinks, $alcool) | |
{ | |
return $this->order | |
->setNumberOfDrinks($numberOfDrinks) | |
->setAlcool($alcool) | |
; | |
} | |
public function updateOrder($numberOfDrinks, $alcool) | |
{ | |
$this->order($numberOfDrinks, $alcool); | |
return $this; | |
} | |
public function receiveDrinks(drinks $drinks) | |
{ | |
$this->drinks = $drinks; | |
return $this; | |
} | |
public function getCreditCardNumber() | |
{ | |
return $this->creditCardNumber; | |
} | |
public function showDrinks() | |
{ | |
foreach ($this->drinks as $drink) | |
{ | |
echo $drink . PHP_EOL; | |
} | |
return $this; | |
} | |
} | |
class tpe | |
{ | |
private $creditCardNumber = ''; | |
private $price = 0; | |
public function setCreditCardNumber($creditCardNumber) | |
{ | |
$this->creditCardNumber = $creditCardNumber; | |
return $this; | |
} | |
public function setPrice($price) | |
{ | |
$this->price = $price; | |
return $this; | |
} | |
public function executeTransaction() | |
{ | |
echo 'Just pay ' . $this->price . ' with card ' . $this->creditCardNumber . '!' . PHP_EOL; | |
return $this; | |
} | |
} | |
class barman | |
{ | |
private $order = null; | |
private $drinks = null; | |
public function receiveOrder(order $order) | |
{ | |
$this->order = $order; | |
return $this; | |
} | |
public function prepareOrder() | |
{ | |
$this->drinks = new drinks(); | |
for ($numberOfDrinks = $this->order->getNumberOfDrinks(); $numberOfDrinks > 0; $numberOfDrinks--) | |
{ | |
$this->drinks->add(new drink($this->order->getAlcool(), 75)); | |
} | |
return $this; | |
} | |
public function giveDrinks() | |
{ | |
return $this->drinks; | |
} | |
public function updateDrinks() | |
{ | |
foreach ($this->drinks as $drink) | |
{ | |
$drink | |
->setAlcool('1664') | |
->setPourcent(10) | |
; | |
} | |
return $this; | |
} | |
public function billDrinks($client) | |
{ | |
$tpe = new tpe(); | |
$tpe | |
->setPrice($this->order->getNumberOfDrinks() * 6) | |
->setCreditCardNumber($client->getCreditCardNumber()) | |
->executeTransaction() | |
; | |
return $this; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment