Skip to content

Commit

Permalink
Lumen does not support a) setting default parameters for a route, b) …
Browse files Browse the repository at this point in the history
…limiting routes by certain regexp
  • Loading branch information
jelhan committed May 24, 2017
1 parent 9151004 commit c49adf8
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 24 deletions.
4 changes: 2 additions & 2 deletions src/Routing/ApiGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@

use CloudCreativity\LaravelJsonApi\Api\ApiResource;
use CloudCreativity\LaravelJsonApi\Api\Definition;
use Illuminate\Contracts\Routing\Registrar;
use Illuminate\Support\Fluent;
use Laravel\Lumen\Application;

/**
* Class ApiGroup
Expand Down Expand Up @@ -53,7 +53,7 @@ class ApiGroup
* @param Definition $apiDefinition
* @param array $options
*/
public function __construct(Registrar $router, Definition $apiDefinition, array $options)
public function __construct(Application $router, Definition $apiDefinition, array $options)
{
$this->router = $router;
$this->apiDefinition = $apiDefinition;
Expand Down
14 changes: 4 additions & 10 deletions src/Routing/RegistersResources.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@

use ArrayAccess;
use CloudCreativity\JsonApi\Utils\Str;
use Illuminate\Contracts\Routing\Registrar;
use Illuminate\Routing\Route;
use Illuminate\Support\Fluent;
use Laravel\Lumen\Application;

/**
* Class RegistersResources
Expand Down Expand Up @@ -129,17 +129,11 @@ protected function hasMany()
* @param $action
* @return Route
*/
protected function createRoute(Registrar $router, $method, $uri, $action)
protected function createRoute(Application $router, $method, $uri, $action)
{
/** @var Route $route */
$route = $router->{$method}($uri, $action);
$route->defaults(ResourceRegistrar::PARAM_RESOURCE_TYPE, $this->resourceType);

if ($idConstraint = $this->idConstraint($uri)) {
$route->where(ResourceRegistrar::PARAM_RESOURCE_ID, $idConstraint);
}

return $route;
$router->{$method}($uri, $action);
return $router;
}

/**
Expand Down
12 changes: 5 additions & 7 deletions src/Routing/RelationshipsGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
namespace CloudCreativity\LaravelJsonApi\Routing;

use Generator;
use Illuminate\Contracts\Routing\Registrar;
use Illuminate\Routing\Route;
use Illuminate\Support\Fluent;
use Laravel\Lumen\Application;

/**
* Class RelationshipsGroup
Expand All @@ -48,7 +48,7 @@ public function __construct($resourceType, Fluent $options)
/**
* @param Registrar $router
*/
public function addRelationships(Registrar $router)
public function addRelationships(Application $router)
{
foreach ($this->relationships() as $relationship => $options) {
foreach ($options['actions'] as $action) {
Expand All @@ -63,18 +63,16 @@ public function addRelationships(Registrar $router)
* @param $action
* @return Route
*/
protected function relationshipRoute(Registrar $router, $relationship, $action)
protected function relationshipRoute(Application $router, $relationship, $action)
{
$route = $this->createRoute(
$this->createRoute(
$router,
$this->routeMethod($action),
$this->routeUrl($relationship, $action),
$this->routeAction($relationship, $action)
);

$route->defaults(ResourceRegistrar::PARAM_RELATIONSHIP_NAME, $relationship);

return $route;
return $router;
}

/**
Expand Down
10 changes: 5 additions & 5 deletions src/Routing/ResourceGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@

use CloudCreativity\JsonApi\Utils\Str;
use CloudCreativity\LaravelJsonApi\Api\ApiResource;
use Illuminate\Contracts\Routing\Registrar;
use Illuminate\Routing\Route;
use Illuminate\Support\Fluent;
use Laravel\Lumen\Application;

/**
* Class ResourceGroup
Expand Down Expand Up @@ -56,7 +56,7 @@ public function __construct($resourceType, ApiResource $apiResource, Fluent $opt
/**
* @param Registrar $router
*/
public function addResource(Registrar $router)
public function addResource(Application $router)
{
$router->group($this->groupAction(), function ($router) {
$this->addResourceRoutes($router);
Expand Down Expand Up @@ -118,7 +118,7 @@ protected function validators()
/**
* @param Registrar $router
*/
protected function addResourceRoutes(Registrar $router)
protected function addResourceRoutes(Application $router)
{
foreach ($this->resourceActions() as $action) {
$this->resourceRoute($router, $action);
Expand All @@ -136,7 +136,7 @@ protected function resourceActions()
/**
* @param Registrar $router
*/
protected function addRelationshipRoutes(Registrar $router)
protected function addRelationshipRoutes(Application $router)
{
$this->relationshipsGroup()->addRelationships($router);
}
Expand All @@ -154,7 +154,7 @@ protected function relationshipsGroup()
* @param $action
* @return Route
*/
protected function resourceRoute(Registrar $router, $action)
protected function resourceRoute(Application $router, $action)
{
return $this->createRoute(
$router,
Expand Down

0 comments on commit c49adf8

Please sign in to comment.