bupy7/xml-constructor
最新稳定版本:v2.0.5
Composer 安装命令:
composer require bupy7/xml-constructor
包简介
The array-like constructor of XML document structure.
README 文档
README
The array-like constructor of XML document structure.
Supporting PHP from 5.6 up to newest.
Install
Add the following to require section of your composer.json:
"bupy7/xml-constructor": "*"
Then do composer install;
or execute the command:
$ composer require bupy7/xml-constructor
Usage
Input:
$xml = new XmlConstructor(); $in = [ [ 'tag' => 'root', 'elements' => [ [ 'tag' => 'tag1', 'attributes' => [ 'attr1' => 'val1', 'attr2' => 'val2', ], ], [ 'tag' => 'tag2', 'content' => 'content2', ], [ 'tag' => 'tag3', 'elements' => [ [ 'tag' => 'tag4', 'content' => 'content4', ], ], ], [ 'tag' => 'tag4', 'content' => '<b>content4</b>', 'cdata' => true, // by default - false, see https://en.wikipedia.org/wiki/CDATA ], ], ], ]; echo $xml->fromArray($in)->toOutput();
Output:
<?xml version="1.0" encoding="UTF-8"?> <root> <tag1 attr1="val1" attr2="val2"/> <tag2>content2</tag2> <tag3> <tag4>content4</tag4> </tag3> <tag4><![CDATA[<b>content4</b>]]></tag4> </root>
Configuration:
$xml = new XmlConstructor([ // Indent each line in the XML document. 4 space by default. 'indentString' => ' ', /* Header document tag. "<?xml version="1.0" encoding="UTF-8"?>" by default. */ 'startDocument' => [ // version '1.0', // encoding 'UTF-8', ], ]);
You can set up indentString and/or startDocument as null to disable them.
Testing
Run tests:
$ ./vendor/bin/phpunit --no-coverage
Run tests with coverage:
$ XDEBUG_MODE=coverage ./vendor/bin/phpunit
HTML coverage path: build/coverage/index.html
Code style
To fix code style, run:
~/.composer/vendor/bin/php-cs-fixer fix --verbose
You have to install PHP CS Fixer at first, if you don't use build-in Docker image:
composer global require friendsofphp/php-cs-fixer
License
xml-constructor is released under the BSD-3-Clause License. See the bundled LICENSE.md for details.
统计信息
- 总下载量: 36.75k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 13
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2015-07-19