Created
June 6, 2012 14:41
-
-
Save andersonfraga/2882304 to your computer and use it in GitHub Desktop.
Fiquei pensando muito sobre o que li, esses dias, quanto à idéia de 'NO-COMPLICATED-CONTROLLERS'. Estou afim de implementar algo do tipo abaixo. Talvez seja bacana. Talvez não...
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 | |
namespace Test; | |
use Eflop\Dispatcher\Router\Handlers\Post; | |
use Eflop\Dispatcher\Router\Register; | |
$register = new Register(); | |
// Home | |
// ANYWHERE METHOD example.com | |
$register->any('/')->accept(['text/html']); | |
// Home | |
// GET example.com | |
$register->get('/') | |
->call(['Test\Model\News', 'list']) | |
->call(['Test\Model\Content', 'list']) // yeah! multiple calls! | |
->cache('1 hour') | |
->accept(['text/html']); | |
// News list | |
// GET example.com/news[.html] | |
$register->get('/news') | |
->call(['Test\Model\News', 'list']) | |
->cache('tomorrow') | |
->accept(['text/html']); | |
// News item | |
// GET example.com/news/1234[.html|.json] | |
$register->get('/news/(?P<id>\d+)') | |
->call( | |
['Test\Model\News', 'getById'], | |
['id'] | |
) | |
->cache('2 days') | |
->accept(['text/html', 'application/json']); | |
// News comment post | |
// POST example.com/news/1234/comment[.html] | |
$register->post('/news/*/comment') | |
->map(['id' => '([0-9]+)']) | |
->call( | |
['Test\Model\Comment', 'saveForNewsId'], | |
['id', Post::INJECT_PARAMETERS] // inject $_POST like second parameter in saveForNewsId method | |
) | |
->accept(['application/json']) | |
->needCSRFKey(true); // need csrf key-protect | |
return $register; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Também tenho interesse em deixar o Respect puramente declarativo, mas ainda falta muito código pra isso! Você já chegou a implementar algum protótipo da tua idéia?