yuubit/paxb 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

yuubit/paxb

最新稳定版本:1.0.1-alpha2

Composer 安装命令:

composer require yuubit/paxb

包简介

Public library PAXB - PHP Annotation Xml Binding, basic implementation of annotation driven xml binding

README 文档

README

PAXB - very basic implementation of annotation driven xml binding

Supported annotations

This lib supports listed bellow annotations:

  • XmlAttribute(name="")
  • XmlElement(name="", type="") - type is required for unmarshaling fields containing objects
  • XmlElementWrapper(name) - name required
  • XmlTransient
  • XmlValue

These annotations could be used only as property annotations or class annotation(XmlElement only)

Sample code

Marshalling example

    /**
     * @XmlElement(name="root")
     */
    class SampleEntity {

        /**
         * @XmlElement(name="attribute-value", type="AttributeValueEntity")
         */
        private $nestedEntity;

        private $text;

        /**
         * @XmlElementWrapper(name="number-list")
         */
        private $number = array();


        public function __construct($number = array(), $nestedEntity = null, $text = "")
        {
            $this->number = $number;
            $this->nestedEntity = $nestedEntity;
            $this->text = $text;
        }
    }

    class AttributeValueEntity {

        /**
         * @XmlAttribute
         */
        private $attribute;

        /**
         * @XmlElement
         */
        private $value;

        /**
         * @param string $attribute
         * @param string $value
         */
        public function __construct($attribute = "", $value = "")
        {
            $this->attribute = $attribute;
            $this->value = $value;
        }

        /**
         * @return string
         */
        public function getAttribute()
        {
            return $this->attribute;
        }

        /**
         * @return string
         */
        public function getValue()
        {
            return $this->value;
        }
    }

Marshalling code:

    $sampleEntity = new SampleEntity(
        array(1,2,3),
        new AttributeValueEntity('sample attribure', 'sample value'),
        'Sample text'
    );

    echo PAXB\Setup::getMarshaller()->marshall($sampleEntity, true);

Output:

    <?xml version="1.0"?>
    <root>
        <attribute-value attribute="sample attribure">
            <value>sample value</value>
        </attribute-value>
        <text>Sample text</text>
        <number-list>
            <number>1</number>
            <number>2</number>
            <number>3</number>
        </number-list>
    </root>

Unmarshalling example

    $xmlInput = '...'; //as above
    /** @var SampleEntity $sampleEntity */
    $sampleEntity = PAXB\Setup::getUnmarshaller()->unmarshall($xmlInput, 'SampleEntity');

Running examples

  1. Install composer: php -r "eval('?>'.file_get_contents('https://getcomposer.org/installer'));"
  2. Install dependencies: ./composer.phar install
  3. run demo script: php demo/demo-marshall.php or php demo/demo-unmarshall.php

统计信息

  • 总下载量: 659
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 4
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-12-31

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固