承接 amberovsky/currency-doctrine 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

amberovsky/currency-doctrine

Composer 安装命令:

composer require amberovsky/currency-doctrine

包简介

Allow the use of amberovsky/currency as a Doctrine field type.

README 文档

README

The amberovsky/currency-doctrine package provides the ability to use amberovsky/currency as a Doctrine field type.

Examples

Configuration

It requires CurrencyFactory to be injected in via CurrencyType::setCurrencyFactory method. Use your current DI mechanism to do that.

To configure Doctrine to use amberovsky/currency as a field type, you'll need to set up the following in your bootstrap:

use Doctrine\DBAL\Types\Type;
use Amberovsky\Money\Currency\Doctrine\CurrencyType;
use Amberovsky\Money\Currency\CurrencyFactory;

$currencyFactory = ...; // Get CurrencyFactory instance somehow

if (!Type::hasType(CurrencyType::NAME)) {
    Type::addType(CurrencyType::NAME, CurrencyType::class);
    /** @var CurrencyType $currencyType */
    $currencyType = Type::getType(CurrencyType::NAME);
    $currencyType->setCurrencyFactory($currencyFactory);
}

Symfony

Add this to your Kernel.php:

    /**
     * @inheritDoc
     */
    protected function initializeContainer() {
        parent::initializeContainer();

        if (!Type::hasType(CurrencyType::NAME)) {
            Type::addType(CurrencyType::NAME, CurrencyType::class);
            /** @var CurrencyType $currencyType */
            $currencyType = Type::getType(CurrencyType::NAME);
            $currencyType->setCurrencyFactory($this->container->get(CurrencyFactory::class));
        }
    }

Usage

Then, in your models, you may annotate properties by setting the @Column type to Currency. Doctrine will handle the rest.

use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity
 * @ORM\Table(name="invoices")
 */
class Invoice
{
    /**
     * @ORM\Column(type="Currency")
     */
    private Currency $currency;

    public function getCurrency(): Currency {
        return $this->currency;
    }
}

How to contribute

Please fork this repo and create a PR. Make sure you run tests before submitting yout PR:

make phpstan
make psalm
make phpspec

License

Copyright (C) 2020 Anton Zagorskii, BSD-3-Clause license, See license file for details

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2020-07-05

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固