-
-
Save nickl-/3104970 to your computer and use it in GitHub Desktop.
Another approach to multiple paths
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 | |
$paths = array( | |
'/users', | |
'/users/*', | |
'/users/*/lists', | |
'/users/*/lists/*', | |
); | |
// Multiple paths handled by single callback | |
$r3->any($paths, function ($userId=null,$listId=null) {/***/} | |
))->by($processors)->when($conditions)->through($formatters)->accept($conneg); | |
// Multiple paths handled by single controller | |
$r3->any($paths, 'MyApp\Controllers\UserController' | |
))->by($processors)->when($conditions)->through($formatters)->accept($conneg); | |
$paths = array( | |
'/users', | |
'/users/*', | |
'/users/*/lists', | |
'/users/*/lists/*', | |
'/user-roles', | |
'/user-roles/*', | |
'/user-roles/*/lists', | |
'/user-roles/*/lists/*', | |
'/user-perms', | |
'/user-perms/*', | |
'/user-perms/*/lists', | |
'/user-perms/*/lists/*', | |
); | |
// Multiple paths handled by single factory | |
// producing different controllers based on path | |
$r3->any($paths, "MyApp\Controllers\iControllerInterface", array('MyApp\Controllers\ControllerFactory', 'getControllerFor') | |
))->by($processors)->when($conditions)->through($formatters)->accept($conneg); | |
Possible implementation for linkTo:
<?php
$r3->any('/administrators/*', function ($adminId=null) {/***/}
))->by($allMeansPossible)->linksTo($userRoute->at('/users/*'), function($data, $link, $adminId) { // $adminId fed by ParamSynced
$data['links'] = array("href" => $link, "title" => "User Page for {$data['name']}");
return $data;
});
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@alganet This could be another approach to providing Router with details pertaining to the paths handled by this route.
Thinking about the hypermedia solution could be:
Well if this be the case then, as fancy as it might be to know all the paths the questions still remain:
As this same example also works without the knowledge of the separate paths and would work as is currently:
Resolving to the controller for users as provided by our controller factory and supplied with the adminId from administrators.
Or am I missing something.