Skip to content

Instantly share code, notes, and snippets.

@JanSuchanek
Created November 2, 2012 07:54
Show Gist options
  • Save JanSuchanek/3999359 to your computer and use it in GitHub Desktop.
Save JanSuchanek/3999359 to your computer and use it in GitHub Desktop.
Prasárna :)
<?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