Created
May 20, 2012 15:15
-
-
Save alganet/2758474 to your computer and use it in GitHub Desktop.
Respect\Transform transforms data friendly to the web
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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 |
I really enjoyed. It will be interesting to see it working.
@jeanpimentel @hussani guys, check this out https://github.com/Respect/Conversion
+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
Curti, e quero ver funcionando.