Skip to content

Instantly share code, notes, and snippets.

@alganet
Created May 20, 2012 15:15
Show Gist options
  • Save alganet/2758474 to your computer and use it in GitHub Desktop.
Save alganet/2758474 to your computer and use it in GitHub Desktop.
Respect\Transform transforms data friendly to the web
<?php
use Respect\Transform\Transformer as t;
$users = array(
array("id" => 1, "first_name" => "Alexandre", "last_name" => "Silva", "location" => "São Paulo"),
array("id" => 2, "first_name" => "Satoshi", "last_name" => "Silva", "location" => "Curitiba"),
array("id" => 3, "first_name" => "Fulano", "last_name" => "Silva", "location" => "New York")
);
$r = t::table()
->column("id")->remove()
->column("last_name")->appendLeft(" ")
->columns("first_name", "last_name")->merge("full_name")
->transform($users);
//each line now is array("full_name" => "Alexandre Silva", "location" => "São Paulo")
$r = t::table()
->column("location")->keep()
->column("location")->duplicate("users_per_location")->count()
->columns("location", "users_per_location")->unique()
->transform($users);
//each line now array("location" => "São Paulo", "users_per_location" => 1)
$r = t::triples()
->subject("rdfs:type")
->table()
->transform($rdfTriples);
$r = t::graph()
->triples()
->transform($graph);
$r = t::array()
->rootNode("venues")
->fathership("venues", "venue")
->fathership("checkins", "checkin")
->attributes("checkin", array("time", "id"))
->attributes("venue", array("name", "id"))
->xml()
->transform($venuesDbResult);
[Component]\[Type]\[Selector]\[Operation]
Transform\Table
Transform\Table\Column
Transform\Table\Column\Remove
Transform\Table\Column\Keep
Transform\Table\Column\Duplicate
Transform\Table\Column\Count
Transform\Table\Columns\Merge
Transform\Table\Columns\Duplicate
Transform\Table\Columns\Sum
Transform\Graph
Transform\Graph\Node
Transform\Graph\Node\Move
Transform\Graph\Nodes
Transform\Triples
@jeanpimentel
Copy link

Curti, e quero ver funcionando.

@hussani
Copy link

hussani commented May 22, 2012

I really enjoyed. It will be interesting to see it working.

@alganet
Copy link
Author

alganet commented Jun 10, 2012

@hussani
Copy link

hussani commented Jun 28, 2012

+1

Crazy functions, many possibilities... great code!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment