Magically transmogrifies arrays into XML documents.
The following software is required for Transmogrifier to run:
- PHP 5.3.2+
Here's how you use it:
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:
<?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>
Depending on your needs, there are a few different ways you can install Transmogrifier:
To add Transmogrifier as a Composer dependency in your composer.json
file:
{
"require": {
"skyzyx/transmogrifier": ">=1.0"
}
}
To install the source code for Transmogrifier:
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:
require_once '/path/to/transmogrifier/src/Skyzyx/Components/Transmogrifier.php';
Alternatively, you can fetch a tarball or zipball:
$ 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:
require_once '/path/to/transmogrifier/src/Skyzyx/Components/Transmogrifier.php';
If you're using a class loader (e.g., Symfony Class Loader) for PSR-0-style class loading:
$loader->registerNamespace('Skyzyx\\Components\\Transmogrifier', 'path/to/vendor/skyzyx/transmogrifier/src/Skyzyx/Components/Transmogrifier');
To view the list of existing contributors, run the following command from the Terminal:
git shortlog -sne --no-merges
Here's the process for contributing:
- 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.
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.
Our unit tests are written in PHPT format. You can run them with either the PEAR Test Runner or with PHPUnit 3.6+.
cd tests/
pear run-tests -r .
...or...
cd tests/
phpunit .
Our integration tests use PHPUnit.
cd tests/
phpunit .
You can generate a code coverage report with the following command. You'll need the Xdebug extension installed:
cd tests/
phpunit --coverage-html ./_coverage_report .
- 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.
Licensed for use under the terms of the MIT license.