Skip to content

Commit c49adf8

Browse files
committed
Lumen does not support a) setting default parameters for a route, b) limiting routes by certain regexp
1 parent 9151004 commit c49adf8

File tree

4 files changed

+16
-24
lines changed

4 files changed

+16
-24
lines changed

src/Routing/ApiGroup.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020

2121
use CloudCreativity\LaravelJsonApi\Api\ApiResource;
2222
use CloudCreativity\LaravelJsonApi\Api\Definition;
23-
use Illuminate\Contracts\Routing\Registrar;
2423
use Illuminate\Support\Fluent;
24+
use Laravel\Lumen\Application;
2525

2626
/**
2727
* Class ApiGroup
@@ -53,7 +53,7 @@ class ApiGroup
5353
* @param Definition $apiDefinition
5454
* @param array $options
5555
*/
56-
public function __construct(Registrar $router, Definition $apiDefinition, array $options)
56+
public function __construct(Application $router, Definition $apiDefinition, array $options)
5757
{
5858
$this->router = $router;
5959
$this->apiDefinition = $apiDefinition;

src/Routing/RegistersResources.php

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020

2121
use ArrayAccess;
2222
use CloudCreativity\JsonApi\Utils\Str;
23-
use Illuminate\Contracts\Routing\Registrar;
2423
use Illuminate\Routing\Route;
2524
use Illuminate\Support\Fluent;
25+
use Laravel\Lumen\Application;
2626

2727
/**
2828
* Class RegistersResources
@@ -129,17 +129,11 @@ protected function hasMany()
129129
* @param $action
130130
* @return Route
131131
*/
132-
protected function createRoute(Registrar $router, $method, $uri, $action)
132+
protected function createRoute(Application $router, $method, $uri, $action)
133133
{
134134
/** @var Route $route */
135-
$route = $router->{$method}($uri, $action);
136-
$route->defaults(ResourceRegistrar::PARAM_RESOURCE_TYPE, $this->resourceType);
137-
138-
if ($idConstraint = $this->idConstraint($uri)) {
139-
$route->where(ResourceRegistrar::PARAM_RESOURCE_ID, $idConstraint);
140-
}
141-
142-
return $route;
135+
$router->{$method}($uri, $action);
136+
return $router;
143137
}
144138

145139
/**

src/Routing/RelationshipsGroup.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
namespace CloudCreativity\LaravelJsonApi\Routing;
2020

2121
use Generator;
22-
use Illuminate\Contracts\Routing\Registrar;
2322
use Illuminate\Routing\Route;
2423
use Illuminate\Support\Fluent;
24+
use Laravel\Lumen\Application;
2525

2626
/**
2727
* Class RelationshipsGroup
@@ -48,7 +48,7 @@ public function __construct($resourceType, Fluent $options)
4848
/**
4949
* @param Registrar $router
5050
*/
51-
public function addRelationships(Registrar $router)
51+
public function addRelationships(Application $router)
5252
{
5353
foreach ($this->relationships() as $relationship => $options) {
5454
foreach ($options['actions'] as $action) {
@@ -63,18 +63,16 @@ public function addRelationships(Registrar $router)
6363
* @param $action
6464
* @return Route
6565
*/
66-
protected function relationshipRoute(Registrar $router, $relationship, $action)
66+
protected function relationshipRoute(Application $router, $relationship, $action)
6767
{
68-
$route = $this->createRoute(
68+
$this->createRoute(
6969
$router,
7070
$this->routeMethod($action),
7171
$this->routeUrl($relationship, $action),
7272
$this->routeAction($relationship, $action)
7373
);
7474

75-
$route->defaults(ResourceRegistrar::PARAM_RELATIONSHIP_NAME, $relationship);
76-
77-
return $route;
75+
return $router;
7876
}
7977

8078
/**

src/Routing/ResourceGroup.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020

2121
use CloudCreativity\JsonApi\Utils\Str;
2222
use CloudCreativity\LaravelJsonApi\Api\ApiResource;
23-
use Illuminate\Contracts\Routing\Registrar;
2423
use Illuminate\Routing\Route;
2524
use Illuminate\Support\Fluent;
25+
use Laravel\Lumen\Application;
2626

2727
/**
2828
* Class ResourceGroup
@@ -56,7 +56,7 @@ public function __construct($resourceType, ApiResource $apiResource, Fluent $opt
5656
/**
5757
* @param Registrar $router
5858
*/
59-
public function addResource(Registrar $router)
59+
public function addResource(Application $router)
6060
{
6161
$router->group($this->groupAction(), function ($router) {
6262
$this->addResourceRoutes($router);
@@ -118,7 +118,7 @@ protected function validators()
118118
/**
119119
* @param Registrar $router
120120
*/
121-
protected function addResourceRoutes(Registrar $router)
121+
protected function addResourceRoutes(Application $router)
122122
{
123123
foreach ($this->resourceActions() as $action) {
124124
$this->resourceRoute($router, $action);
@@ -136,7 +136,7 @@ protected function resourceActions()
136136
/**
137137
* @param Registrar $router
138138
*/
139-
protected function addRelationshipRoutes(Registrar $router)
139+
protected function addRelationshipRoutes(Application $router)
140140
{
141141
$this->relationshipsGroup()->addRelationships($router);
142142
}
@@ -154,7 +154,7 @@ protected function relationshipsGroup()
154154
* @param $action
155155
* @return Route
156156
*/
157-
protected function resourceRoute(Registrar $router, $action)
157+
protected function resourceRoute(Application $router, $action)
158158
{
159159
return $this->createRoute(
160160
$router,

0 commit comments

Comments
 (0)