Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/katmore/micro-encode
xml encoder and html generator
https://github.com/katmore/micro-encode
encoder encoding html-generation html-generator php php-library php7 phpunit-tests vanilla-php xml-serialization
Last synced: 24 days ago
JSON representation
xml encoder and html generator
- Host: GitHub
- URL: https://github.com/katmore/micro-encode
- Owner: katmore
- License: mit
- Created: 2017-12-01T04:05:10.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2018-12-06T00:59:08.000Z (about 6 years ago)
- Last Synced: 2024-12-05T21:45:12.546Z (28 days ago)
- Topics: encoder, encoding, html-generation, html-generator, php, php-library, php7, phpunit-tests, vanilla-php, xml-serialization
- Language: PHP
- Homepage:
- Size: 64.5 KB
- Stars: 2
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# MicroEncode
xml encoder and html generator## Installation
use composer to add **MicroEncode** to your PHP project:
```
composer require katmore/micro-encode
```## Usage
* [Encoding data to XML](#xmlencoder-usage) - XmlEncoder Usage
* [Generating HTML from data](#htmlencoder-usage) - HtmlEncoder Usage### XmlEncoder Usage
The [`XMLEncoder`](./src/MicroEncode/XmlEncoder.php) class serializes an XML document from arbitrary data. The [PHP data types](http://php.net/manual/en/language.types.intro.php) supported are: [`boolean`](http://php.net/manual/en/language.types.boolean.php), [`integer`](http://php.net/manual/en/language.types.integer.php), [`float`](http://php.net/manual/en/language.types.float.php), [`string`](http://php.net/manual/en/language.types.string.php), [`array`](http://php.net/manual/en/language.types.array.php), [`object`](http://php.net/manual/en/language.types.object.php), and [`null`](http://php.net/manual/en/language.types.null.php). The XML document conforms to the [Flat XML Schema](https://github.com/katmore/flat/wiki/xmlns) specification.The following is an example of encoding associative array data into an XML document:
```php
$myData = [
'my_example_1'=>'my 1st data value',
'my_example_2'=>'my 2nd data value',
];echo (new \MicroEncode\XmlEncoder($myData));
```
The above code should output the following XML:
```xmlmy 1st data value
my 2nd data value```
### HtmlEncoder Usage
The [`HtmlEncoder`](./src/MicroEncode/HtmlEncoder.php) class generates HTML from arbitrary data. The [PHP data types](http://php.net/manual/en/language.types.intro.php) supported are: [`boolean`](http://php.net/manual/en/language.types.boolean.php), [`integer`](http://php.net/manual/en/language.types.integer.php), [`float`](http://php.net/manual/en/language.types.float.php), [`string`](http://php.net/manual/en/language.types.string.php), [`array`](http://php.net/manual/en/language.types.array.php), [`object`](http://php.net/manual/en/language.types.object.php), and [`null`](http://php.net/manual/en/language.types.null.php).The following is an example of generating HTML from associative array data:
```php
$myData = [
'my_example_1'=>'my 1st data value',
'my_example_2'=>'my 2nd data value',
];echo (new \MicroEncode\HtmlEncoder($myData));
```
The above code should output the following HTML:
```html
-
my_example_1: my 1st data value -
my_example_2: my 2nd data value
```
The above HTML would render into set of unordered list items as follows:
* my_example_1: my 1st data value
* my_example_2: my 2nd data value
## Unit Tests
* [`coverage.txt`](./coverage.txt): unit test coverage report
* [`phpunit.xml`](./phpunit.xml): PHPUnit configuration file
* [`tests/Unit`](./tests/Unit): source code for unit tests
To perform unit tests, execute phpunit located in the `vendor/bin` directory.
```sh
vendor/bin/phpunit
```
The [`tests.sh`](./tests.sh) wrapper script is provided for convenience.
```sh
./tests.sh
```
## Legal
### Copyright
MicroEncode - https://github.com/katmore/micro-encode
Copyright (c) 2012-2018 Doug Bird. All Rights Reserved.
### License
MicroEncode is copyrighted free software.
You may redistribute and modify it under either the terms and conditions of the
"The MIT License (MIT)"; or the terms and conditions of the "GPL v3 License".
See [LICENSE](https://github.com/katmore/micro-encode/blob/master/LICENSE) and [GPLv3](https://github.com/katmore/micro-encode/blob/master/GPLv3).