Created
November 2, 2012 07:54
-
-
Save JanSuchanek/3999359 to your computer and use it in GitHub Desktop.
Prasárna :)
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 | |
namespace Kedrigern\Price; | |
header('Content-Type: text/html; charset=utf-8'); | |
class PriceEntity { | |
private $acceptable = array( | |
"CZK", "EUR", "USD" | |
); | |
private $amount; | |
public function __construct(){ | |
foreach($this->acceptable as $key => $row){ | |
$this->amount[$row] = 0; | |
} | |
} | |
public function setAmount($amount, $type){ | |
if(in_array($type, $this->acceptable)){ | |
$this->amount[$type] += (double)$amount; | |
} | |
} | |
} | |
abstract class Currency { | |
public static function convert() | |
{ | |
echo "Něco s tím prověď něbo se zblázním :)"; | |
} | |
} | |
class Price extends Currency { | |
protected $priceEntity; | |
protected function createPriceEntity(){ | |
if(!$this->priceEntity){ | |
$this->priceEntity = new PriceEntity(); | |
} | |
} | |
public function add($amount, $type = "CZK"){ | |
$this->createPriceEntity(); | |
$this->priceEntity->setAmount($amount,$type); | |
} | |
} | |
$currency = new Price(); | |
$currency->add(3000,"USD"); | |
$currency->add(2000,"CZK"); | |
$prices = $currency->convert(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment