Comments (5)
I did some edits to make it work,
Undo the changes and update to the latest version using composer update
and follow these instructions : DingoAPI Integration
Let me know if everything is working good.
from lumen-route-binding.
Hi,
I reviewed Dingo code and found that they re-bound the FastRoute dispatcher that's why LumenRouteBinding dispatcher is not being called ..
To make it work it will need some workaround,
You will need to extend this Dingo
class Dingo\Api\Routing\Adapter\Lumen
and create the following class & put it somewhere, maybe in app/Custom
:
// app/Custom/DingoAdapter.php
namespace App\Custom;
use Illuminate\Http\Request;
use Dingo\Api\Exception\UnknownVersionException;
use Dingo\Api\Routing\Adapter\Lumen as BaseDingoAdapter;
class DingoAdaptre extends BaseDingoAdapter
{
/**
* The dispatcher resolver callable.
*
* @var callable
*/
protected $dispatcherResolver;
/**
* Set callable to get dispatcher instance.
*
* @param callable $dispatcherResolver
*/
public function setDispatcherResolver(callable $dispatcherResolver) {
$this->dispatcherResolver = $dispatcherResolver;
}
/**
* Dispatch a request.
*
* @param \Illuminate\Http\Request $request
* @param string $version
*
* @return mixed
*/
public function dispatch(Request $request, $version)
{
if (! isset($this->routes[$version])) {
throw new UnknownVersionException;
}
$this->removeMiddlewareFromApp();
$routes = $this->routes[$version];
$this->app->setDispatcher(
call_user_func($this->dispatcherResolver, $routes->getData())
);
$this->normalizeRequestUri($request);
return $this->app->dispatch($request);
}
}
Then replace app/Providers/RouteBindingServiceProvider.php
with the following :
// app/Providers/RouteBindingServiceProvider.php
namespace App\Providers;
use App\Custom\DingoAdaptre;
use mmghv\LumenRouteBinding\BindingResolver;
use mmghv\LumenRouteBinding\FastRouteDispatcher;
use FastRoute\RouteParser\Std as StdRouteParser;
use FastRoute\DataGenerator\GroupCountBased as GcbDataGenerator;
use mmghv\LumenRouteBinding\RouteBindingServiceProvider as BaseServiceProvider;
class RouteBindingServiceProvider extends BaseServiceProvider
{
/**
* Boot the service provider
*/
public function boot()
{
// The binder instance
$binder = $this->binder;
// Here we define our bindings
}
/**
* Register the service provider.
*/
public function register()
{
// Register our binding resolver in the service container
$this->binder = new BindingResolver([$this->app, 'make']);
$this->app->instance('bindingResolver', $this->binder);
// replace dingo adapter which was set by dingo to allow for route binding,
// this provider needs to be registered after dingo is registered
$this->setDingoAdapter();
}
/**
* Replace dingo adapter in the container.
*/
protected function setDingoAdapter()
{
$this->app->singleton('api.router.adapter', function ($app) {
$adapter = new DingoAdaptre($app, new StdRouteParser, new GcbDataGenerator, '');
$adapter->setDispatcherResolver(function($data) {
return $this->getDispatcher($data);
});
return $adapter;
});
}
/**
* Get LumenRoutebinding dispatcher instance
*
* @param array $data
*
* @return FastRouteDispatcher
*/
public function getDispatcher($data)
{
// Create a new FastRoute dispatcher (our extended one)
$dispatcher = new FastRouteDispatcher(null);
$dispatcher->setBindingResolver($this->binder);
$dispatcher->setDispatcherResolver(function($dispatcher) use ($data) {
return new $dispatcher($data);
});
return $dispatcher;
}
}
IMPORTANT Make sure to register App\Providers\RouteBindingServiceProvider
after Dingo
provider NOT before it.
Please let me know if it worked ..
from lumen-route-binding.
Thanks for your reply.I put the same code in my project.And I did register RouteBindingServiceProvider
after Dingo
provider.It's still not work.Maybe I should go back to use Laravel.
from lumen-route-binding.
That's cool.It works now!Thank you so much!
from lumen-route-binding.
You're welcome, glad to help :)
from lumen-route-binding.
Related Issues (13)
- Lumen 7.x support HOT 1
- Laravel 8 Support HOT 2
- Binding Not working HOT 1
- Lumen 8 Binding Not working HOT 9
- Support for Lumen 9.x HOT 1
- Class 'app/Providers/RouteBindingServiceProvider' not found HOT 4
- Undefined variable: binder HOT 1
- Lumen 5.5 Support HOT 1
- "dingo/api" Integration
- Access bound model in FormRequest HOT 1
- Route binding and auth middleware HOT 1
- Route binding always run before middleware HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from lumen-route-binding.