milo/schematron
Composer 安装命令:
composer require milo/schematron
包简介
Implementation of ISO Schematron with Schematron 1.5 back compatibility. Library does not need any XSLT.
README 文档
README
This library is an implementation of the ISO Schematron (with Schematron 1.5 back compatibility). It is done by pure DOM processing and does not require any XSLT sheets nor XSLT PHP extension. It was a requirement for a development.
Usage
Install the Schematron by the Composer or download a release package.
require 'src/Schematron.php'; use Milo\Schematron; $schematron = new Schematron; $schematron->load('schema.xml'); $document = new DOMDocument; $document->load('document.xml'); $result = $schematron->validate($document); var_dump($result);
Format of the Schematron::validate() result depends on its second argument. E.g. an imaginary results:
# Flat array of failed asserts and successful reports (it is default) $result = $schematron->validate($document, Schematron::RESULT_SIMPLE); # array (2) # 0 => "Person must have surname." # 1 => "Phone number is required." # More complex structure $result = $schematron->validate($document, Schematron::RESULT_COMPLEX); # array (3) # 0 => stdClass (2) # title => "Pattern 1" (9) # rules => array (3) # 2 => stdClass (2) # context => "/" # errors => array (2) # 0 => stdClass (3) # | test => "false()" (7) # | message => "S5 - fail" (9) # | path => "/" # 1 => stdClass (3) # test => "true()" (6) # message => "S6 - fail" (9) # path => "/" # Or throws exception of first error occurence try { $result = $schematron->validate($document, Schematron::RESULT_EXCEPTION); } catch (Milo\SchematronException $e) { echo $e->getMessage(); # Person must have surname. }
A validation phase can be passed by 3rd argument:
$schematron->validate($document, Schematron::RESULT_SIMPLE, 'phase-base-rules');
Schematron performs a schema namespace (ISO or v1.5) autodetection but the namespace can be passed manually:
$schematron = new Schmeatron(Schematron::NS_ISO);
By Schematron::setOptions($options) you can adjust the Schematron behaviour. The $options is a mask of following flags:
# Allows to schema does not contain a <sch:schema> element, # so <pattern>s stands alone in XML, e.g. in Relax NG schema Schematron::ALLOW_MISSING_SCHEMA_ELEMENT # <sch:include> are ignored and do not expand Schematron::IGNORE_INCLUDE # <sch:include> are forbidden and loading fails if occures Schematron::FORBID_INCLUDE # <sch:rule> with the same @context as any rule before is skipped # This arises from official Universal Tests (http://www.schematron.com/validators/universalTests.sch) Schematron::SKIP_DUPLICIT_RULE_CONTEXT # <sch:schema> needn't to contain <sch::pattern>s Schematron::ALLOW_EMPTY_SCHEMA # <sch:pattern> needn't to contain <sch::rule>s Schematron::ALLOW_EMPTY_PATTERN # <sch:rule> needn't to contain <sch:assert>s nor <sch:report>s Schematron::ALLOW_EMPTY_RULE
An <sch:include> processing is affected by setting Schematron::setAllowedInclude($allowed) mask which permits types of include uri and Schematron::setMaxIncludeDepth($depth):
# Remote URLs Schematron::INCLUDE_URL # Absolute and relative filesystem paths Schematron::INCLUDE_ABSOLUTE_PATH Schematron::INCLUDE_RELATIVE_PATH # Any URI Schematron::INCLUDE_ALL
And two basic attributes of loaded schema are accesible over:
$schematron->getSchemaVersion(); $schematron->getSchemaTitle();
Licence
You may use all files under the terms of the New BSD Licence, or the GNU Public Licence (GPL) version 2 or 3, or the MIT Licence.
Tests
The Schematron tests are written for Nette Tester. Two steps are required to run them:
# Download the Tester tool composer.phar update --dev # Run the tests vendor/bin/tester tests
milo/schematron 适用场景与选型建议
milo/schematron 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 368.21k 次下载、GitHub Stars 达 18, 最近一次更新时间为 2013 年 07 月 22 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 milo/schematron 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 milo/schematron 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 368.21k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 19
- 点击次数: 23
- 依赖项目数: 3
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2013-07-22