Skip to content

Commit

Permalink
Support Lumen 10
Browse files Browse the repository at this point in the history
  • Loading branch information
mmghv committed Apr 13, 2023
1 parent 4bd5545 commit 58618a9
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
composer.phar
/vendor/
.vscode
.phpunit.result.*

# We ignore the lock file to allow tests to be done on the latest supported versions of Lumen and FastRoute
composer.lock
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -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%20--%209-orange.svg)](https://github.com/laravel/lumen)
[![Lumen Version](https://img.shields.io/badge/Lumen-5%20--%2010-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 - 9).
This package Adds support for `Route Model Binding` in Lumen (5 - 10).

> 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 [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 FastRoute in Lumen.
Expand All @@ -30,7 +30,7 @@ composer require mmghv/lumen-route-binding "^1.0"
> It requires
> ```
> php >= 7.1
> Lumen 5 - 9
> Lumen 5 - 10
> ```
#### Register the service provider
Expand Down Expand Up @@ -91,7 +91,7 @@ $binder->bind('user', 'App\User');
This way, Anywhere in our routes if the wildcard `{user}` is found, It will be resolved to the `User` model instance that corresponds to the wildcard value, So we can define our route like this :

```PHP
$app->get('profile/{user}', function(App\User $user) {
$router->get('profile/{user}', function(App\User $user) {
//
});
```
Expand Down Expand Up @@ -158,7 +158,7 @@ $binder->implicitBind('App');
So in this example :

```PHP
$app->get('articles/{article}', function($myArticle) {
$router->get('articles/{article}', function($myArticle) {
//
});
```
Expand Down Expand Up @@ -196,7 +196,7 @@ $binder->implicitBind('App\Repositories', 'Eloquent', 'Repository');
So in this example :

```PHP
$app->get('articles/{article}', function($myArticle) {
$router->get('articles/{article}', function($myArticle) {
//
});
```
Expand Down Expand Up @@ -224,7 +224,7 @@ $binder->implicitBind('App\Repositories', '', 'Repository', 'findForRoute');
2- defining our route in `routes.php` :

```PHP
$app->get('articles/{article}', function(App\Article $article) {
$router->get('articles/{article}', function(App\Article $article) {
return view('articles.view', compact('article'));
});
```
Expand Down Expand Up @@ -254,7 +254,7 @@ Similar to explicit binding, We can handle the exception thrown in the resolver
Sometimes, you will have a route of two or more levels that contains wildcards of related models, Something like :

```PHP
$app->get('posts/{post}/comments/{comment}', function(App\Post $post, App\Comment $comment) {
$router->get('posts/{post}/comments/{comment}', function(App\Post $post, App\Comment $comment) {
//
});
```
Expand Down Expand Up @@ -316,5 +316,5 @@ Pull Requests are welcome, just make sure to follow the PSR-2 standards and don'

## License & Copyright

Copyright © 2016-2017, [Mohamed Gharib](https://github.com/mmghv).
Copyright © 2016-2023, [Mohamed Gharib](https://github.com/mmghv).
Released under the [MIT license](LICENSE).
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
],
"require": {
"php": "~7.1|~8.0",
"laravel/lumen-framework": "5 - 9",
"laravel/lumen-framework": "5 - 10",
"nikic/fast-route": ">=0.4 <2.0"
},
"require-dev": {
Expand Down
6 changes: 6 additions & 0 deletions tests/BindingResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@

class BindingResolverTest extends TestCase
{
private $model;
private $myTestRepo;
private $wildcards;
private $expected;
private $binder;

public function setUp(): void
{
$this->resetBinder();
Expand Down
4 changes: 4 additions & 0 deletions tests/FastRouteDispatcherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@

class FastRouteDispatcherTest extends TestCase
{
private $routeData;
private $binder;
private $dispatcher;

public static function setUpBeforeClass(): void
{
// Setup stub for FastRoute dispatcher class
Expand Down

0 comments on commit 58618a9

Please sign in to comment.