定制 fykosak/nette-fks-utils 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

fykosak/nette-fks-utils

最新稳定版本:v0.2.1.0

Composer 安装命令:

composer require fykosak/nette-fks-utils

包简介

README 文档

README

Lines of codePHPPSR-12

Currency & Price

Currency.php

Something like enum :) Methods cases, tryFrom, from and property value similar like enum(PHP8.1). Implemented is only EUR and CZK.

To format amount use method format(float $amount):string

Price.php

Representation of single currency price. Currency is passed as required parameter of constructor and can not be changed. If amount is not present in constructor, will be set to 0.0. To modify amount use method add, to substrate use add with negative amount.

$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'

Method __toString is only delegate to Currency::format().

MultiCurrencyPrice

Represent container for price in more Currencies at the same time.

Base usage

$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

Operation add

$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

BaseComponent

BaseComponent represent nette Nette\Application\UI\Control with possibility use nette/DI inject like in Presenters.

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 ;)
    }
} 

统计信息

  • 总下载量: 68.85k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 2
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 5
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-3.0-or-later
  • 更新时间: 2020-12-05

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固