Transmogrifier
Magically transmogrifies arrays into XML documents., (*1)
Requirements
Required
The following software is required for Transmogrifier to run:, (*2)
Examples
Here's how you use it:, (*3)
use Transmogrifier\Transmogrifier;
$data = array(
'book' => array(
array(
'author' => 'Author0',
'title' => 'Title0',
'publisher' => 'Publisher0',
'__attributes__' => array(
'isbn' => '978-3-16-148410-0'
)
),
array(
'author' => array('Author1', 'Author2'),
'title' => 'Title1',
'publisher' => 'Publisher1'
),
array(
'__attributes__' => array(
'isbn' => '978-3-16-148410-0'
),
'__content__' => 'Title2'
)
)
);
echo Transmogrifier::toXML($data);
Which gives you the following:, (*4)
<?xml version="1.0"?>
<root>
<book isbn="978-3-16-148410-0">
<author><![CDATA[Author0]]></author>
<title><![CDATA[Title0]]></title>
<publisher><![CDATA[Publisher0]]></publisher>
</book>
<book>
<author><![CDATA[Author1]]></author>
<author><![CDATA[Author2]]></author>
<title><![CDATA[Title1]]></title>
<publisher><![CDATA[Publisher1]]></publisher>
</book>
<book isbn="978-3-16-148410-0"><![CDATA[Title2]]></book>
</root>
Installation
Depending on your needs, there are a few different ways you can install Transmogrifier:, (*5)
Bundle with Composer
To add Transmogrifier as a Composer dependency in your composer.json
file:, (*6)
{
"require": {
"skyzyx/transmogrifier": ">=1.0"
}
}
Install source from GitHub
To install the source code for Transmogrifier:, (*7)
git clone git://github.com/skyzyx/transmogrifier.git
cd transmogrifier
wget --quiet http://getcomposer.org/composer.phar
php composer.phar install
And include it in your scripts:, (*8)
require_once '/path/to/transmogrifier/src/Skyzyx/Components/Transmogrifier.php';
Install source from zip/tarball
Alternatively, you can fetch a tarball or zipball:, (*9)
$ curl https://github.com/skyzyx/transmogrifier/tarball/master | tar xzv
(or)
$ wget https://github.com/skyzyx/transmogrifier/tarball/master -O - | tar xzv
And include it in your scripts:, (*10)
require_once '/path/to/transmogrifier/src/Skyzyx/Components/Transmogrifier.php';
Using a Class Loader
If you're using a class loader (e.g., Symfony Class Loader) for PSR-0-style class loading:, (*11)
$loader->registerNamespace('Skyzyx\\Components\\Transmogrifier', 'path/to/vendor/skyzyx/transmogrifier/src/Skyzyx/Components/Transmogrifier');
Contributing
To view the list of existing contributors, run the following command from the Terminal:, (*12)
git shortlog -sne --no-merges
How?
Here's the process for contributing:, (*13)
- Fork Transmogrifier to your GitHub account.
- Clone your GitHub copy of the repository into your local workspace.
- Write code, fix bugs, and add tests with 100% code coverage.
- Commit your changes to your local workspace and push them up to your GitHub copy.
- You submit a GitHub pull request with a description of what the change is.
- The contribution is reviewed. Maybe there will be some banter back-and-forth in the comments.
- If all goes well, your pull request will be accepted and your changes are merged in.
- You will become "Internet famous" with anybody who runs
git shortlog
from the Terminal. :)
To simplify many aspects of development, we also have a build.xml
for Phing. The easiest way to install Phing and any other dependencies is to install Phix., (*14)
Testing
, (*15)
Requests strives to have 100% code-coverage of the library with an extensive set of tests. We're not quite there yet, but we're getting close., (*16)
Unit tests
Our unit tests are written in PHPT format. You can run them with either the PEAR Test Runner or with PHPUnit 3.6+., (*17)
cd tests/
pear run-tests -r .
...or..., (*18)
cd tests/
phpunit .
Integration tests
Our integration tests use PHPUnit., (*19)
cd tests/
phpunit .
Code Coverage
You can generate a code coverage report with the following command. You'll need the Xdebug extension installed:, (*20)
cd tests/
phpunit --coverage-html ./_coverage_report .
Authors, Copyright & Licensing
- Copyright (c) 2010-2012 Ryan Parman.
- Copyright (c) 2012 Amazon.com, Inc. or its affiliates.
See also the list of contributors who participated in this project., (*21)
Licensed for use under the terms of the MIT license., (*22)