DASPRiD/Dash — pull request #46 by bakura10 (2014-05-10 20:24:59+00:00)
Title: Allow to let routes decide if they can assemble

ping @ocramius

Hi,

This PR tries to solve an issue I have with ZfrRest. With ZF2 router and current Dash, the only way to assemble a route is to know its name:

```php
$path = $router->assemble([], ['name' => 'users']); // prints /users
```

However, routes are not always that simple. For instance, ZfrRest routes automatically traverses a hierarchy and can generate URI far beyond that what was defined in the "route" option. For instance, if a user has an association called "tweets", if you only define the "users" route with a "/users" path, ZfrRest may generate a lot of different URI: /users, /users/1, /users/2/tweets...

Because those routes are not actually defined in the config, there is currently no way to actually generate those URL without ugly hacks. What I'd like is actually letting my routes to decide if they can assemble something (based on parameters, options...). I could, for instance, use the router as follow:

```php
$path = $router->assemble(['template' => '/users/{user_id}/tweets']);
```

The route could then decide to accept or reject the option. If the route returns true to "canAssemble", then the router let the given route to assemble.