Skip to content

Commit 667a14d

Browse files
authored
3.x - Wrap routes in the default config (#127)
* Wrap routes in the default config * Backward compatibility * Apply fixes from StyleCI (#128)
1 parent a2b00d6 commit 667a14d

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

src/Repositories/Repository.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,11 @@ public function __call($method, $parameters)
186186
*
187187
* @param Router $router
188188
* @param array $attributes
189+
* @param bool $wrap Choose the routes defined in the @routes method, should be wrapped in a group with attributes by default.
190+
* If true then all routes will be grouped in a configuration attributes passed by restify, otherwise
191+
* you should take care of that, by adding $router->group($attributes) in the @routes method
189192
*/
190-
public static function routes(Router $router, $attributes)
193+
public static function routes(Router $router, $attributes, $wrap = false)
191194
{
192195
$router->group($attributes, function ($router) {
193196
// override for custom routes

src/RestifyCustomRoutesProvider.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,18 @@ protected function registerRoutes()
4141

4242
$parameters = $method->getParameters();
4343

44-
if (count($parameters) === 2 && $parameters[1] instanceof \ReflectionParameter) {
45-
// $config = array_merge($config, $parameters[1]->getDefaultValue());
44+
$wrap = [];
45+
46+
if (count($parameters) >= 2 && $parameters[1] instanceof \ReflectionParameter) {
47+
$default = $parameters[1]->isDefaultValueAvailable() ? $parameters[1]->getDefaultValue() : [];
48+
$config = array_merge($config, $default);
49+
}
50+
51+
if (count($parameters) === 3) {
52+
$wrap = ($parameters[2]->isDefaultValueAvailable() && $parameters[2]->getDefaultValue()) ? $config : [];
4653
}
4754

48-
Route::group([], function ($router) use ($repository, $config) {
49-
if ($repository === 'Binaryk\LaravelRestify\Tests\RepositoryWithRoutes') {
50-
}
55+
Route::group($wrap, function ($router) use ($repository, $config) {
5156
$repository::routes($router, $config);
5257
});
5358
});

0 commit comments

Comments
 (0)