basilicom / xml-tool-bundle
本插件为Pimcore提供xml(导出)工具。
v1.3.1
2022-02-01 10:19 UTC
Requires
- pimcore/pimcore: >=5.0 <7.0
- spatie/array-to-xml: ^2.12
Requires (Dev)
- codeception/codeception: ^2.2
Suggests
- ext-xsl: Needed to support XSLT transformations via --xslt option
This package is auto-updated.
Last update: 2024-08-29 05:53:52 UTC
README
为处理XML数据添加命令。目前,可以递归地导出对象树,保留层次结构。
可以通过控制台命令触发导出,并将结果写入stdout、文件或pimcore资产。
如果启用,也可以通过REST API提供导出功能。
目录
许可
GPLv3 - 查看:LICENSE
要求
- PHP >= 7.1
- Pimcore >= 5.0.0
- XSL PHP扩展以支持--xslt选项
安装
- 使用composer安装插件:
composer require basilicom/xml-tool-bundle dev-master。 - 执行
bin/console pimcore:bundle:enable BasilicomXmlToolBundle
配置
n/a
控制台使用
使用导出命令导出对象树,例如路径 /foo
bin/console basilicom:xmltool:export /foo
示例输出
注意:在示例中,对象树 /foo 包含一个对象类 Bar 的单个对象,该对象具有单个输入属性 name。
Exporting tree of Objects starting at /foo
<?xml version="1.0"?>
<root id="1" type="folder" key="" class="Folder">
<:children>
<Bar id="4" type="object" key="baaaar" class="Bar">
<name><![CDATA[bar]]></name>
</Bar>
</:children>
</root>
复杂示例
- 不要导出通过关系附加的对象的属性/字段
- 导出对象的变体
- 将根节点名称更改为 'Products'
- 应用示例xslt
- 导出到pimcore资产
/output/my-export.xml
./bin/console basilicom:xmltool:export --omit-relation-object-fields --include-variants --root=products --asset=/output/my-export.xml --xslt sample.xsl /exp
示例XSLT
<?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <objects> <xsl:for-each select="//Leaf"> <object> <name><xsl:value-of select="name"/></name> </object> </xsl:for-each> </objects> </xsl:template> </xsl:stylesheet>
有关所有选项(写入文件等),请参阅
bin/console basilicom:xmltool:export --help
使用:REST API
为了启用REST API,在 app/config/local/xmltool.yml 中放置一个配置文件
basilicom_xml_tool: api: enabled: true endpoints: test1: token: secrettoken0815 root: Products # Root name of the exported XML file path: /export/products # Path to the exporting objects xslt: ../sample.xsl include_variants: true omit_relation_object_fields: true test2: path: /sample/obj/path
此示例启用了两个端点URL
- https://PIMCORE-SERVER/xml-tool/export/test1?token=secrettoken0815
- https://PIMCORE-SERVER/xml-tool/export/test2
限制
目前只支持少数字段类型
- input
- select
- wysiwyg
- textarea
- date
- datetime
- ManyToManyObjectRelation
- color
- rgbaColor
- localizedFields
为了扩展支持的类型,在 Service/Xml.php 中实现一个 getForType* 方法。