2017 © Pedro Peláez
 

library php-xml-convertible

PHP Xml Convertible Object Trait

image

horat1us/php-xml-convertible

PHP Xml Convertible Object Trait

  • Thursday, March 22, 2018
  • by Horat1us
  • Repository
  • 2 Watchers
  • 1 Stars
  • 364 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 14 Versions
  • 38 % Grown

The README.md

Simple trait that converts your object to DOMElement (XML)

Build Status Code Coverage Scrutinizer Code Quality Latest Stable Version Latest Unstable Version License Total Downloads, (*1)

  1. Trait
  2. Interface
  3. Examples

This trait automatically converts your object to XML representation (DOMElement). All your public properties (you can override method getXmlProperties) will be converted to attributes., (*2)

To declare children in your object you need to set $xmlChildren property.
To change element name you need to set $xmlElementName property (short class name will be used by default), (*3)

Install

composer require horat1us/php-xml-convertible

Test

make test

Usage

You should just declare your class to implement Horat1us\XmlConvertibleInterface and use Horat1us\\XmlConvertible trait:, (*4)

name = $array['name'] ?? null;
        $object->surname = $array['surname'] ?? null;

        return $object;
    }
}
```


## About

This trait and interface can be useful when you create object than parse something and
 represents XML structure, like:
 
#### XmlConvertible::toXml [Example 1](./examples/toXml.php) 
 ```php
toXml($document);
$document->appendChild($element);
echo $document->saveXml();
 ```
Will output:
 ```xml

<Person name="Alexander" surname="Letnikow"/>
 ```

#### XmlConvertible::fromXml [Example 2](./examples/fromXml.php) 
```php

<Person name="Alexander" surname="Letnikow"><Head size="big" mind="small" /></Person>';

$document = new \DOMDocument;
$document->loadXML($xml);
$person = Person::fromXml($document);
echo print_r($person, true);

Will output:, (*5)

Horat1us\Examples\Person Object
(
    [name] => Alexander
    [surname] => Letnikow
    [xmlChildren] => Array
        (
            [0] => Horat1us\XmlConvertibleObject Object
                (
                    [xmlChildren] => Array
                        (
                        )

                    [xmlElementName] => Head
                    [size] => big
                    [mind] => small
                )

        )

    [xmlElementName] => Person
)

See tests to know more about all features., (*6)

License

This project is open-sourced software licensed under the MIT license, (*7)

The Versions

22/03 2018

dev-master

9999999-dev

PHP Xml Convertible Object Trait

  Sources   Download

MIT

The Requires

 

The Development Requires

by Alexander Letnikow

22/03 2018

1.4.0

1.4.0.0

PHP Xml Convertible Object Trait

  Sources   Download

MIT

The Requires

 

The Development Requires

by Alexander Letnikow

06/08 2017

1.3.3

1.3.3.0

PHP Xml Convertible Object Trait

  Sources   Download

MIT

The Requires

 

The Development Requires

by Alexander Letnikow

17/07 2017

1.3.2

1.3.2.0

PHP Xml Convertible Object Trait

  Sources   Download

MIT

The Requires

 

The Development Requires

by Alexander Letnikow

11/05 2017

1.3.1

1.3.1.0

PHP Xml Convertible Object Trait

  Sources   Download

MIT

The Requires

 

The Development Requires

by Alexander Letnikow

11/05 2017

1.0.0-rc1

1.0.0.0-RC1

PHP Xml Convertible Object Trait

  Sources   Download

MIT

The Requires

 

The Development Requires

by Alexander Letnikow

11/05 2017

1.3.0

1.3.0.0

PHP Xml Convertible Object Trait

  Sources   Download

MIT

The Requires

 

The Development Requires

by Alexander Letnikow

04/05 2017

1.2.1

1.2.1.0

PHP Xml Convertible Object Trait

  Sources   Download

MIT

The Requires

 

The Development Requires

by Alexander Letnikow

04/05 2017

dev-scrutinizer-patch-1

dev-scrutinizer-patch-1

PHP Xml Convertible Object Trait

  Sources   Download

MIT

The Requires

 

The Development Requires

by Alexander Letnikow

04/05 2017

1.2.0

1.2.0.0

PHP Xml Convertible Object Trait

  Sources   Download

MIT

The Requires

 

The Development Requires

by Alexander Letnikow

04/05 2017

dev-develop

dev-develop

PHP Xml Convertible Object Trait

  Sources   Download

MIT

The Requires

 

The Development Requires

by Alexander Letnikow

02/05 2017

1.1.0

1.1.0.0

PHP Xml Convertible Object Trait

  Sources   Download

MIT

The Requires

 

The Development Requires

by Alexander Letnikow

01/05 2017

1.0.1

1.0.1.0

PHP Xml Convertible Object Trait

  Sources   Download

MIT

The Requires

 

The Development Requires

by Alexander Letnikow

01/05 2017

1.0.0

1.0.0.0

PHP Xml Convertible Object Trait

  Sources   Download

MIT

The Requires

 

The Development Requires

by Alexander Letnikow