Skip to content

Commit 255c72c

Browse files
author
Lupacescu Eduard
authored
Injecting Handler only when restify request (thought the RestifyInjector)
Patch 1
2 parents 802a37a + 2752332 commit 255c72c

File tree

3 files changed

+22
-17
lines changed

3 files changed

+22
-17
lines changed

config/config.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,15 @@
6565
| Restify Exception Handler
6666
|--------------------------------------------------------------------------
6767
|
68-
| These will override the main application exception handler,
69-
| set to null, it will not override it.
70-
| Having RestifyHandler as a global exception handler is a good approach, since it
68+
| The exception handler will be attached to any Restify "CRUD" route.
69+
| It will not be attached to custom routes defined in yours Restify Repositories,
70+
| if you want to have it for all of the routes, can extend RestifyHandler
71+
| from your application App\Exceptions\Handler.
72+
|
73+
| These will override the main application exception handler, set to null, it will not override it.
74+
| Having RestifyHandler as a global exception handler is a good recommendation since it
7175
| will return the exceptions in an API pretty format.
76+
|
7277
*/
7378
'exception_handler' => \Binaryk\LaravelRestify\Exceptions\RestifyHandler::class,
7479
];

src/RestifyApplicationServiceProvider.php

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace Binaryk\LaravelRestify;
44

5-
use Illuminate\Contracts\Debug\ExceptionHandler;
65
use Illuminate\Support\Facades\Gate;
76
use Illuminate\Support\ServiceProvider;
87

@@ -14,7 +13,6 @@ class RestifyApplicationServiceProvider extends ServiceProvider
1413
public function boot()
1514
{
1615
$this->authorization();
17-
$this->registerExceptionHandler();
1816
$this->repositories();
1917
}
2018

@@ -32,18 +30,6 @@ protected function repositories()
3230
Restify::repositoriesFrom(app_path('Restify'));
3331
}
3432

35-
/**
36-
* Register Restify's custom exception handler.
37-
*
38-
* @return void
39-
*/
40-
protected function registerExceptionHandler()
41-
{
42-
if (config('restify.exception_handler') && class_exists(value(config('restify.exception_handler')))) {
43-
$this->app->bind(ExceptionHandler::class, value(config('restify.exception_handler')));
44-
}
45-
}
46-
4733
/**
4834
* Configure the Restify authorization services.
4935
*

src/RestifyServiceProvider.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Binaryk\LaravelRestify;
44

5+
use Illuminate\Contracts\Debug\ExceptionHandler;
56
use Illuminate\Support\Facades\Route;
67
use Illuminate\Support\ServiceProvider;
78

@@ -17,6 +18,7 @@ class RestifyServiceProvider extends ServiceProvider
1718
public function boot()
1819
{
1920
$this->registerRoutes();
21+
$this->registerExceptionHandler();
2022
}
2123

2224
/**
@@ -48,4 +50,16 @@ public function defaultRoutes($config)
4850

4951
return $this;
5052
}
53+
54+
/**
55+
* Register Restify's custom exception handler.
56+
*
57+
* @return void
58+
*/
59+
protected function registerExceptionHandler()
60+
{
61+
if (config('restify.exception_handler') && class_exists(value(config('restify.exception_handler')))) {
62+
$this->app->bind(ExceptionHandler::class, value(config('restify.exception_handler')));
63+
}
64+
}
5165
}

0 commit comments

Comments
 (0)