-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRoutingServiceProvider.php
61 lines (52 loc) · 1.63 KB
/
RoutingServiceProvider.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
namespace Dingo\Api\Provider;
use Dingo\Api\Routing\Router;
use Illuminate\Support\Collection;
use Dingo\Api\Routing\UrlGenerator;
use Dingo\Api\Routing\ControllerDispatcher;
use Illuminate\Routing\RoutingServiceProvider as ServiceProvider;
class RoutingServiceProvider extends ServiceProvider
{
/**
* Boot the service provider.
*
* @return void
*/
public function boot()
{
$this->replaceBoundRouter();
$this->replaceBoundUrlGenerator();
}
/**
* Replace the bound router.
*
* @return void
*/
protected function replaceBoundRouter()
{
$this->app->bindShared('router', function ($app) {
$router = new Router($app['events'], $app['api.config'], $app);
if ($app['env'] == 'testing') {
$router->disableFilters();
}
$router->setControllerDispatcher(new ControllerDispatcher($router, $app));
$router->setConditionalRequest($app['config']->get('api::conditional_request'));
$router->setStrict($app['config']->get('api::strict'));
return $router;
});
}
/**
* Replace the bound URL generator.
*
* @return void
*/
protected function replaceBoundUrlGenerator()
{
$this->app->bindShared('url', function ($app) {
$routes = Collection::make($app['router']->getRoutes())->merge($app['router']->getApiGroups()->getRoutes());
return new UrlGenerator($routes, $app->rebinding('request', function ($app, $request) {
$app['url']->setRequest($request);
}));
});
}
}