2017 © Pedro Peláez
 

project ook

A package that transforms XML/JSON documents from one standard to another

image

brianseitel/ook

A package that transforms XML/JSON documents from one standard to another

  • Tuesday, April 26, 2016
  • by brianseitel
  • Repository
  • 1 Watchers
  • 1 Stars
  • 608 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Ook

A translator for XML/JSON files using a YAML or JSON configuration., (*1)

What is "Ook"?

In the Discworld series by Larry Niven, the Librarian is a wizard turned into an orangutan early in the series. He understands Morporkian (English) perfectly well, but always speaks in orangutan, using words like "Ook" and "Eek". Most human characters have little trouble understanding this, but every now and again someone unfamiliar with the Librarian meets him and cannot quite figure out what that particular "Ook" meant. The Librarian tried to address this issue by writing an Orangutan-Morpokian dictionary, but has not progressed beyond "Ook" yet., (*2)

Oh, I see.

Yeah, pretty funny, right?, (*3)

Quick Start

Define a configuration

Ook utilizes the "dot" notation when defining rules for translating between arrays. Here's a quick example of what dot notation is:, (*4)


$array = ['items' => [ 'item' => [ ['name' => 'computer', 'price' => 1000], ['name' => 'monitor', 'price' => 150] ] ]; Arr::get('items.item.0.price') // 1000

We'll use the same thing to define a ruleset for XML:, (*5)

sample.xml

<items>
    <item>
        <name>computer</name>
        <price>1000</price>
    </item>
    <item>
        <name>monitor</name>
        <price>150</price>
    </item>
</items>

Ook will convert this to an array with a key of item.price. Let's imagine we want to translate this from item.price to inventory.item.price, (*6)

config.yaml

inventory.item.*.name: items.item.*.name
inventory.item.*.price: items.item.*.price

To translate it, we simply run:, (*7)


$librarian = new Ook\Librarian('sample.xml', 'config.yaml'); $output = $librarian->transform();

This will return:, (*8)

Array
(
    [inventory] => Array
        (
            [item] => Array
                (
                    [0] => Array
                        (
                            [name] => computer
                            [price] => 1000
                        )

                    [1] => Array
                        (
                            [name] => monitor
                            [price] => 150
                        )

                )

        )

)

Additional Details

Check out the /examples directory for more samples., (*9)

The Versions

26/04 2016

dev-master

9999999-dev

A package that transforms XML/JSON documents from one standard to another

  Sources   Download

MIT

The Requires

 

The Development Requires