定制 formatd/importer 二次开发

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

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

formatd/importer

Composer 安装命令:

composer require formatd/importer

包简介

This package provides an XML-Importer for Neos Flow entities.

README 文档

README

This package provides an XML-Importer for Neos Flow entities.

What does it do?

This package provides an XML-Importer for Neos Flow entities. By creating an XML following a specific structure you can for example create fixtures for tests or use it to import data and resources into the system for which you do not have a frontend for editing data. You can also import the entities only into memory and choose not to persist them (useful for test fixtures for example).

Running the import

Importing a simple file as one-time-import:

    ./flow import:xml /path/to/xml-file.xml

Import and updates

If you would like to later on update data you have previously imported you can use an optional parameter to inject the UUIDs into the imported XMLs. That way if you change it and import it again the entities are updated and not created again.

    ./flow import:xml /path/to/xml-file.xml --enableXmlModification

It is possible to reference other entities in the xml by specifying a id. If you have already imported stuff you can load this data into memory so that all references are loaded.

    ./flow import:xml /path/to/xml-file.xml --initializePathAndFilename="/path/to/other/files/with"

Using importer for test fixtures

The importer can be used as a convenient way to create fixtures for functional or end-to-end testing.

If you need some data in a functional test you can do something like this:

   
    $importService->setPersistenceEnabled(FALSE);
    $importService->importFromFile('/path/to/file');
    $fixture = $importService->getImportedObjectByReference(My\Package\Domain\Model\ShippingRate:class, 'standard');
    

XML Structure for import files

Basic Example

Here is an example of a simple import-file. This creates two shippingRate entities and two timeFrame entities referencing one of the shipping rates.

<?xml version="1.0" encoding="UTF-8"?>
<data>
	<meta>
		<repository type="My\Package\Domain\Model\ShippingRate" repositoryName="My\Package\Domain\Repository\ShippingRateRepository" />
		<repository type="My\Package\Domain\Model\TimeFrame" repositoryName="My\Package\Domain\Repository\TimeFrameRepository" />
		<repository type="Neos\Flow\Security\Account" repositoryName="Neos\Flow\Security\AccountRepository" />
	</meta>
	<content>
	
	    <!--  Arbitrary named nodes. The inner nodes are iterated and need a type property -->
	    <shippingRates>
	        <!-- specify an optional id=".." if you want to reference the imported entity later on -->
			<shippingRate id="standard" type="My\Package\Domain\Model\ShippingRate">
				<properties>
					<name>Standard</name>
					<level type="integer">3</level>
					<cost type="double">3.90</cost>
				</properties>
			</shippingRate>
			<shippingRate id="stundengenau" type="My\Package\Domain\Model\ShippingRate">
				<properties>
					<name>Stundengenau</name>
					<level type="integer">4</level>
					<cost type="double">5.90</cost>
				</properties>
			</shippingRate>
		</shippingRates>

	    <timeFrames>
			<timeFrame id="8-9" type="My\Package\Domain\Model\TimeFrame">
				<properties>
					<name>8 - 9 Uhr</name>
					<startTime type="DateTime">
						<constructorArguments>
							<arg1>08:00:00</arg1>
						</constructorArguments>
					</startTime>
					<duration type="integer">1</duration>
					<defaultCapacity type="integer">5</defaultCapacity>
					<defaultShippingRate reference="stundengenau" type="My\Package\Domain\Model\ShippingRate" />
				</properties>
			</timeFrame>
			<timeFrame id="9-10" type=">My\Package\Domain\Model\TimeFrame">
				<properties>
					<name>9 - 10 Uhr</name>
					<startTime type="DateTime">
						<constructorArguments>
							<arg1>09:00:00</arg1>
						</constructorArguments>
					</startTime>
					<duration type="integer">1</duration>
					<defaultCapacity type="integer">5</defaultCapacity>
					<defaultShippingRate reference="stundengenau" type="My\Package\Domain\Model\ShippingRate" />
				</properties>
			</timeFrame>
		</timeFrames>
		
	</content>
</data>

The section <meta> contains only a mapping what repository is used for which entity. The <content> section contains arbitrary named sections such as <shippingRates> in our example. These Sections themselves contain multiple sections with a type="" attribute.

It is possible to split the imported data into multiple files prefixed by a 3 digit number (be aware that the files are sorted before import). You have to take care that referenced entities are already imported before referencing them.

    000_MetaData.xml    
    010_ShippingRates.xml
    020_TimeFrames.xml

Nesting and Relations

It is possible to define relations (ManyToMany or OneToMany) in a seperate section <relations>:

...
        <rule type="My\Package\Domain\Model\Rule">
            <properties>
                <active type="boolean">TRUE</active>
                <name>Some rule to manage the TimeFrame 8-9</name>
                <priority type="integer">100</priority>
                <capacity type="integer">50</capacity>
                <shippingRate reference="stundengenau" type="My\Package\Domain\Model\ShippingRate" />
            </properties>
            <relations>
                <zone reference="some-alrerady-imported-zone" type="My\Package\Domain\Model\Zone"  />
                <timeFrame reference="8-9" type="My\Package\Domain\Model\TimeFrame" />
                <timeFrame reference="9-10" type="My\Package\Domain\Model\TimeFrame" />
            </relations>
        </rule>
...

The importer works recursively and also imports nested structures:

...
        <rule type="My\Package\Domain\Model\Rule">
            <properties>
                ...
            </properties>
            <relations>
                <zone reference="some-alrerady-imported-zone" type="My\Package\Domain\Model\Zone"  />
                <timeFrame reference="8-9" type="My\Package\Domain\Model\TimeFrame" />
                <timeFrame reference="9-10" type="My\Package\Domain\Model\TimeFrame" />
                <!-- this would also be possible: -->
                <timeFrame id="10-11" type=">My\Package\Domain\Model\TimeFrame">
                    <properties>
                        <name>10 - 11 Uhr</name>
                        <startTime type="DateTime">
                            <constructorArguments>
                                <arg1>10:00:00</arg1>
                            </constructorArguments>
                        </startTime>
                        <duration type="integer">1</duration>
                        <defaultCapacity type="integer">5</defaultCapacity>
                        <defaultShippingRate type="My\Package\Domain\Model\ShippingRate" >
                            <properties>
                                <name>Some other Rate</name>
                                <level type="integer">6</level>
                                <cost type="double">19.90</cost>
                            </properties>
                        </defaultShippingRate>
                    </properties>
                </timeFrame>
            </relations>
        </rule>
...

formatd/importer 适用场景与选型建议

formatd/importer 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 5 次下载、GitHub Stars 达 0, 最近一次更新时间为 2019 年 09 月 18 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 formatd/importer 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 formatd/importer 我们能提供哪些服务?
定制开发 / 二次开发

基于 formatd/importer 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-09-18