From 58618a9128c0e3a14882654342ac8a6b6a13d454 Mon Sep 17 00:00:00 2001 From: mmghv Date: Thu, 13 Apr 2023 00:50:20 +0000 Subject: [PATCH] Support Lumen 10 --- .gitignore | 1 + README.md | 18 +++++++++--------- composer.json | 2 +- tests/BindingResolverTest.php | 6 ++++++ tests/FastRouteDispatcherTest.php | 4 ++++ 5 files changed, 21 insertions(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index 98bd575..11c6f8f 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/README.md b/README.md index 5823218..ee3d2cb 100644 --- a/README.md +++ b/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%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. @@ -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 @@ -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) { // }); ``` @@ -158,7 +158,7 @@ $binder->implicitBind('App'); So in this example : ```PHP -$app->get('articles/{article}', function($myArticle) { +$router->get('articles/{article}', function($myArticle) { // }); ``` @@ -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) { // }); ``` @@ -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')); }); ``` @@ -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) { // }); ``` @@ -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). diff --git a/composer.json b/composer.json index 9ede855..82e4027 100644 --- a/composer.json +++ b/composer.json @@ -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": { diff --git a/tests/BindingResolverTest.php b/tests/BindingResolverTest.php index 22fc5f7..37c671c 100644 --- a/tests/BindingResolverTest.php +++ b/tests/BindingResolverTest.php @@ -7,6 +7,12 @@ class BindingResolverTest extends TestCase { + private $model; + private $myTestRepo; + private $wildcards; + private $expected; + private $binder; + public function setUp(): void { $this->resetBinder(); diff --git a/tests/FastRouteDispatcherTest.php b/tests/FastRouteDispatcherTest.php index afd2eb5..04e65c9 100644 --- a/tests/FastRouteDispatcherTest.php +++ b/tests/FastRouteDispatcherTest.php @@ -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