i4erkasov / phalcon-xml-annotations
Phalcon XML Annotations
v1.0.0
2023-06-01 22:34 UTC
Requires
- php: >=7.4
- ext-phalcon: ^4.0
- ext-psr: ^1
- ext-xmlwriter: *
Requires (Dev)
- phpunit/phpunit: ^9.6
README
Phalcon XML Annotations 是一个库,允许您将 PHP 对象转换为 XML 文件。它提供注解来定义 XML 文件的结构和参数,基于 PHP 对象。
安装
您可以使用 Composer 安装 Phalcon XML Annotations 库。只需在您的项目中运行以下命令
composer require i4erkasov/phalcon-xml-annotations
文档
⚠️ 文档正在开发中:这个库正在积极开发中,文档目前正在创建中。我们为任何不便之处表示歉意。请参阅源代码和示例以获取使用说明和实现细节。感谢您的理解。
使用示例
请参阅 example 目录以获取上下文。
代码
<?php use ExamplePhalconXML\IrishPub; use I4\Phalcon\XML\Analyzer; use I4\Phalcon\XML\XmlAnnotations; use Phalcon\Annotations\Adapter\Memory; $annotations = new XmlAnnotations( new Analyzer(new Memory()) ); $xml = $annotations->parse( new IrishPub( 'The Shamrock Pub', 'Dublin, Ireland', '10:00 AM', '2:00 AM' ) ); $xml->setExtraAttributes([ 'Beer' => [ 'Date' => (new DateTime('now'))->format('Y-m-d'), ] ]); echo $xml->getString(); // Returns the XML as a string echo $xml->save('/tmp/file.xml'); // Saves the generated XML to a file
结果
<?xml version="1.0" encoding="UTF-8"?> <XML> <IrishPub Name="The Shamrock Pub" Address="Dublin, Irelan" OpeningTime="10:00 AM" ClosingTime="2:00 AM"> <![CDATA[Irish Pub]]> <BeerList> <Beer Date="2023-06-02" Brand="Guinness" Type="Stout" ABV="4.2" Country="Ireland"/> <Beer Date="2023-06-02" Brand="Smithwick's" Type="Red Ale" ABV="4.5" Country="Ireland"/> <Beer Date="2023-06-02" Brand="Harp Lager" Type="Lager" ABV="4.5" Country="Ireland"/> </BeerList> </IrishPub> </XML>
贡献
您可以通过创建问题、建议新功能以及向 GitHub 仓库提交拉取请求来为这个库的开发做出贡献。
许可协议
Phalcon XML Annotations 在 MIT 许可协议 下发布。