Skip to content

Commit

Permalink
Update to support Lumen5.5
Browse files Browse the repository at this point in the history
  • Loading branch information
mmghv committed Sep 11, 2017
1 parent b6dfa39 commit 42ee5ea
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Expand Up @@ -5,6 +5,7 @@ php:
- 5.5
- 5.6
- 7.0
- 7.1

script:
- composer install
Expand Down
8 changes: 4 additions & 4 deletions README.md
@@ -1,13 +1,13 @@
# Lumen Route Binding

[![Build Status](https://travis-ci.org/mmghv/lumen-route-binding.svg?branch=master)](https://travis-ci.org/mmghv/lumen-route-binding)
[![Lumen Version](https://img.shields.io/badge/Lumen-5.0%20to%205.4-orange.svg)](https://github.com/laravel/lumen)
[![Lumen Version](https://img.shields.io/badge/Lumen-5.0%20to%205.5-orange.svg)](https://github.com/laravel/lumen)
[![Latest Stable Version](https://poser.pugx.org/mmghv/lumen-route-binding/v/stable)](https://packagist.org/packages/mmghv/lumen-route-binding)
[![Total Downloads](https://poser.pugx.org/mmghv/lumen-route-binding/downloads)](https://packagist.org/packages/mmghv/lumen-route-binding)
[![Latest Unstable Version](https://poser.pugx.org/mmghv/lumen-route-binding/v/unstable)](https://packagist.org/packages/mmghv/lumen-route-binding)
[![License](https://poser.pugx.org/mmghv/lumen-route-binding/license)](LICENSE)

This package Adds support for `Route Model Binding` in Lumen (5.0 to 5.4).
This package Adds support for `Route Model Binding` in Lumen (5.0 to 5.5).

> As known, Lumen doesn't support `Route Model Binding` out of the box due to the fact that Lumen doesn't use the Illuminate router that Laravel uses, Instead, It uses the [FastRoute](https://github.com/nikic/FastRoute) which is much faster. With this package, We add support for the powerful `Route Model Binding` while still benefit the speed of the FastRoute in Lumen.
Expand Down Expand Up @@ -35,7 +35,7 @@ composer require mmghv/lumen-route-binding "^1.0"
#### Register the service provider

You have 2 options, continue reading ..
In the coming section ..


## Usage
Expand All @@ -44,7 +44,7 @@ You have 2 options, continue reading ..
### Where to Define our Bindings

As mentioned before, You have 2 options :
You have 2 options :

#### OPTION 1

Expand Down
15 changes: 14 additions & 1 deletion src/RouteBindingServiceProvider.php
Expand Up @@ -60,11 +60,24 @@ protected function getRoutesResolver()
$routeCollector = new RouteCollector(new RouteParser, new DataGenerator);

// Get routes data from application
foreach ($this->app->getRoutes() as $route) {
foreach ($this->getRoutes() as $route) {
$routeCollector->addRoute($route['method'], $route['uri'], $route['action']);
}

return $routeCollector->getData();
};
}

/**
* Get routes data.
*
* @return array
*/
protected function getRoutes()
{
// Support lumen < 5.5 by checking for the router property.
$router = property_exists($this->app, 'router') ? $this->app->router : $this->app;

return $router->getRoutes();
}
}
4 changes: 3 additions & 1 deletion tests/IntegratedTest.php
Expand Up @@ -26,8 +26,10 @@ public function testRouteBindingAndItsServiceProviderWorksAsExpectedWithLumen()
return "{$val} Resolved";
});

$router = isset($app->router) ? $app->router : $app;

// Register a route with a wildcard
$app->get('/{wildcard}', function ($wildcard) {
$router->get('/{wildcard}', function ($wildcard) {
return response($wildcard);
});

Expand Down

0 comments on commit 42ee5ea

Please sign in to comment.