harmbandstra/edexmllib

PHP 库,用于验证和导入 Edexml 文件。

2.0.0 2022-12-01 21:07 UTC

This package is auto-updated.

Last update: 2024-08-29 04:25:34 UTC


README

PHP 库,用于验证和导入 Edexml 文件。

安装

使用 composer 安装

$ composer require harmbandstra/edexmllib

使用方法

    $xml = file_get_contents('path_to_file');
    try {
        $edex = EdexmlFactory::load($xml);
    } catch (ValidationException $exception) {
        // Handle exception
    }

    foreach ($edex->getGroepen()->getGroep() as $groep) {
        echo $groep->getNaam();
    }

    foreach ($edex->getLeerlingen() as $leerling) {
        echo $leerling->getGebruikersnaam();
    }

如果 Edexml 文件包含在非公共 XSD 中定义类型的元素,您可以在加载 XML 之前删除该块。

    $xml = file_get_contents('path_to_file');
    try {
        $edex = EdexmlFactory::load(
            EdexmlFactory::stripToevoegingen($xml)
        );
    } catch (ValidationException $exception) {
        // Handle exception
    }

要跳过验证,将 strict 设置为 false

    $xml = file_get_contents('path_to_file');
    $edex = EdexmlFactory::load($xml, false);

开发

该库使用 xsd2php 生成 JMS Serializer 定义文件。这些文件用于将 XML 反序列化为小块 PHP 对象。

生成类

要基于 XSD 文件生成新的类和 JMS Serializer 配置,请运行

php vendor/bin/xsd2php convert config.yml src/Resources/xsd/*.xsd

仅在规范更改时需要这样做。