Created
November 2, 2012 08:03
-
-
Save JanSuchanek/3999394 to your computer and use it in GitHub Desktop.
a nebo
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; | |
} | |
} | |
} | |
interface Currency { | |
public static function convert(); | |
} | |
class Price implements 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); | |
} | |
public static function convert() | |
{ | |
echo "Něco s tím prověď něbo se zblázním :)"; | |
} | |
} | |
$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