Skip to content

Instantly share code, notes, and snippets.

@alganet
Created July 11, 2012 19:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save alganet/3092803 to your computer and use it in GitHub Desktop.
Save alganet/3092803 to your computer and use it in GitHub Desktop.
<?php
//Sketch 1
$r3->any(array(
'/users' => 'MyApp\Controllers\UsersCollection',
'/users/*' => 'MyApp\Controllers\UsersResource',
'/users/*/lists' => 'MyApp\Controllers\UsersCollection\ListsCollection',
'/users/*/lists/*' => 'MyApp\Controllers\UsersCollection\ListsResource',
'/posts/*/*/*' => 'MyApp\Controllers\PostsResource'
))->by($processors)->when($conditions)->through($formatters)->accept($conneg);
//Sketch 2 (alternative to 1)
$r3->namespaceRoute('MyApp\Controllers'); //based on conventions shown on Sketch 1
@nickl-
Copy link

nickl- commented Jul 11, 2012

Also translates to:

<?php
//Sketch 1

$routes = array(
    '/users' => 'MyApp\Controllers\UsersCollection',
    '/users/*' => 'MyApp\Controllers\UsersResource',
    '/users/*/lists' => 'MyApp\Controllers\UsersCollection\ListsCollection',
    '/users/*/lists/*' => 'MyApp\Controllers\UsersCollection\ListsResource',
    '/posts/*/*/*' => 'MyApp\Controllers\PostsResource'
);
foreach ($routes as $path => $callback)
    $r3->any($path, $callback)->by($processors)->when($conditions)->through($formatters)->accept($conneg);

//Sketch 2 (alternative to 1)
$r3->namespaceRoute('MyApp\Controllers'); //based on conventions shown on Sketch 1

Which the pandas can already do without any help from us.
concerns:

  • It just doesn't make sense to create all that overhead.
  • What if I don't know the info about $routes at design time I'm just adding new ones
  • again the question remains
    • what exactly do we want to do with $routes
    • what have we lost not knowing the actual paths

because remember we still know there is an any catch all /** that we have to call for all and it can also spawn anything defined in $routes, what do we know more about that?

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