se/opentrans-bundle

此包将opentrans库集成到Symfony2中。允许从PHP创建与OpenTRANS兼容的文档。

v0.1.5 2020-10-21 09:14 UTC

This package is not auto-updated.

Last update: 2024-09-19 03:07:57 UTC


README

Latest Stable Version SensioLabsInsight

此包将 [opentrans] (https://github.com/sveneisenschmidt/opentrans) 库集成到Symfony2。

开发分支是master分支。

Build Status

目录

安装

配置

使用

测试

安装

推荐的安装方法是使用 Composer

{
    "require": {
        "se/opentrans-bundle": "dev-master"
    }
}

将包添加到您的AppKernel.php文件中

// in AppKernel::registerBundles()
$bundles = array(
    // ...
    new SE\Bundle\OpenTransBundle\SEOpenTransBundle(),
    // ...
);

配置

您可以在应用程序配置中声明默认文档。(例如,app/config/config.yml)

se_open_trans:

  documents:

    my_default_order_document:
      type: order
      document:
        header:
          control_info:
            generator_info: "My Order Document"

    my_default_order_document_2:
      type: order
      document:
        header:
          control_info:
            generator_info: "My Order Document 2"
          order_info:
            custom_key: custom_var
            my_shop_id: Magento_1702

使用

您的配置文档构建器作为成员在 se.opentrans.document_builder_manager 服务中可用。通过调用 $manager->getDocumentBuilder($documentName) 来检索它。

$manager = $container->get('se.opentrans.document_builder_manager');
$builder = $manager->getDocumentBuilder('my_default_order_document');
$document = $builder->getDocument();

文档构建器也作为服务创建。因此,您可以直接从容器中加载文档构建器,而不是调用文档构建器管理器。名称由基本键 se.opentrans.document_builder. 和您配置中的 se_open_trans.documents 键组成。(例如,my_default_order_document

$builder = $container->get('se.opentrans.document_builder.my_default_order_document');
$document = $builder->getDocument();

运行测试

$> vendor/bin/phpunit