arsengoian/commerce-ml

简单易用的 CommerceML 2.10 PHP 库

dev-master 2020-11-27 11:04 UTC

This package is auto-updated.

Last update: 2024-09-27 19:26:51 UTC


README

简单且无要求的基于 SimpleXML 的 CommerceML 解析器和构建器。

特性

用法

 composer require arsengoian/commerce-ml

解析 CommerceML

use CommerceML\Client;
/**
 * @var string $input
 */
$commercialInformation = Client::toCommerceML($input);

从 CommerceML 对象构建 CommerceML 字符串

use CommerceML\Client;
/**
 * @var CommerceML\Implementation\CommercialInformation $commercialInformation
 */
$output = Client::toString($commercialInformation);

命名空间

  • CommerceML\Nodes - 代表节点的抽象类。可能具有自定义实现,包括数据库存储
  • CommerceML\Implementation - 最简单的实现,将变量存储在受保护字段中。在解析时将返回此实现。收集数组的节点还实现了 ArrayAccessIteratorAggregateCountable
  • CommerceML\Constructors - 具有构造函数的实现,扩展自 CommerceML\Implementation。在构建自定义 CommerceML 树时使用这些实现。

高级

要在解析时使用自定义类,在调用 Client::toString() 之前,请执行以下操作:

use CommerceML\Node\Node

Node::overrideImplementations([
    ProductCustomImplementation::class, // Must inherit from CommerceML\Implementations\Product
]);

贡献

当前库的实现并未涵盖所有可能的 CommerceML 节点。例如,产品导入节点没有被涵盖。

也欢迎完整的测试覆盖率。