Last active
December 11, 2015 16:08
-
-
Save nicmart/4625632 to your computer and use it in GitHub Desktop.
I have to choose the more elegant interface for selectors for the treebuilder library.
Here I post some alternatives to se how they look like.
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 | |
// Current interface | |
$tree | |
->leaf('element', 'author') | |
->key('value', 'author_name') | |
->value('element', 'name') | |
->end() | |
->leaf('element', 'date') | |
->value(function(\DateTime $dateTime) { return $dateTime->format('d-m-Y'); }) | |
->key('value', 'born in') | |
->end() | |
->leaf() | |
->key('value', 'short description') | |
->value(function($book) { | |
$date = $book['date']; | |
return sprintf('"%s": a book by %s written in %s', | |
$book['title'], | |
$book['author']['name'], | |
$book['date']->format('Y') | |
); | |
}) | |
->end() | |
->each('element', 'related') | |
->key('value', 'related titles') | |
->leaf() | |
->value('element', 'title') | |
->end() | |
->end() | |
; |
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 | |
// default PA but no resolver | |
$tree | |
->leaf('author') | |
->key(new Value('author_name')) | |
->value('element', 'name') | |
->end() | |
->leaf('date') | |
->value(function(\DateTime $dateTime) { return $dateTime->format('d-m-Y'); }) | |
->key(new Value('born in')) | |
->end() | |
->leaf() | |
->key(new Value('short description')) | |
->value(function($book) { | |
$date = $book['date']; | |
return sprintf('"%s": a book by %s written in %s', | |
$book['title'], | |
$book['author']['name'], | |
$book['date']->format('Y') | |
); | |
}) | |
->end() | |
->each('related') | |
->key(new Value('related titles')) | |
->leaf() | |
->value('title') | |
->end() | |
->end() | |
; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment