PHP code example of fykosak / nette-fks-utils

1. Go to this page and download the library: Download fykosak/nette-fks-utils library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

fykosak / nette-fks-utils example snippets


$price = new Price(Currency::from(Currency::CZK), 4.5);
$price->add(5.0);
$price->add(-4.0);
$price->getAmount(); // return 5.5
$price->getCurrency();// return Currency object with value 'czk'

$multiPrice = new MultiCurrencyPrice([new Price(Currency::from(Currency::CZK), 4)]); // Create container with only CZK price and amout 4.0 CZK
$multiPrice->czk; // Price can be access wia magic __get, an key is ISO 4217 3char code and return Price object
$multiPrice->eur; // Throw \OutOfRangeException, Price in EUR is not set 

$multiPrice->czk = new Price(Currency::from(Currency::CZK)); // via magic __set can be set price
$multiPrice->czk = new Price(Currency::from(Currency::EUR)); // thow exception currecies muss be same

$multiPrice->eur = new Price(Currency::from(Currency::EUR)); // thow exception because EUR price is not present, only curencies registred in contructor can be used

$multiPrice1 = new MultiCurrencyPrice([
    new Price(Currency::from(Currency::CZK), 2),
]);
$multiPrice2 = new MultiCurrencyPrice([
    new Price(Currency::from(Currency::CZK), 1),
    new Price(Currency::from(Currency::EUR), 4),
]);

$multiPrice1->add($multiPrice2); // can be added because curencies of $multiprice1 is a subset of $multiprice2
$multiPrice1->eur; // but still thow exception and not added a new currency 
$multiPrice1->czk->getAmount(); // is 3.0 call add on Prices

$multiPrice2->add($multiPrice1); // thow exeption because $multiprice1 no contains eur, so $multiprice2 is not a subset of the $multiprice1


class MyComponent extends \Fykosak\Utils\BaseComponent\BaseComponent
{
    private MyService $myService;
    public function injectMyService(MyService $myService):void
    {
        $this->myService = $myService; // works with BaseComponent in components too ;)
    }
}