Reputation: 757
I've got several Lumen services that have the same code inside the render()
function within the App\Exceptions\Handler.php
class. I want to move this code to a separate package that all of the services can include. I was able to get this working by making the package Handler.php file extend the Laravel\Lumen\Exceptions\Handler.php
class, basically inserting my class between the default framework file and the Handler that users edit.
Change:
class Handler extends Laravel\Lumen\Exceptions\Handler {...}
To:
My class
use Laravel\Lumen\Exceptions\Handler;
class MyHandler extends Handler {...}
Framework class
use ServiceHelpers\Exceptions\MyHandler;
class Handler extends MyHandler {...}
However I ran into the problem where Laravel\Lumen\Exceptions\Handler
doesn't exist when unit testing my file within the package. I've requires several illuminate/...
packages in my composer file but it looks like the file I'm trying to extend is in the Laravel or Lumen framework and I'd have to require the laravel/lumen
package which I don't think is appropriate.
I'm currently have the following required:
"illuminate/support": "^5.5",
"illuminate/http": "^5.5",
"illuminate/validation": "^5.5",
The error I'm getting is:
[Symfony\Component\Debug\Exception\FatalErrorException]
Class 'Laravel\Lumen\Exceptions\Handler' not found
Upvotes: 0
Views: 518
Reputation: 62338
Well, technically, your package depends on laravel/lumen-framework
being installed, since it is extending a class from that package. Because of this, having laravel/lumen-framework
as a dependency for your package is appropriate; your package depends on it being installed.
Upvotes: 1