I am writing a bridge in laravel between a library and laravel it's self and I thought the best way was to write a service provider package. It would be a package with one class that looks like:
<?php
namespace Eve\Service\Provider;
use Illuminate\Support\ServiceProvider;
use EveOnline\Items\Details;
class EveMarketProvider extends ServiceProvider {
protected $defer = true;
/**
* Register the application services.
*
* @return void
*/
public function register()
{
$this->app->singleton(Details::class, function ($app) {
return new Details();
});
... // More classes.
}
public function provides()
{
return [
Details::class,
... // More classes.
];
}
}
The goal is the be able to do (in the Laravel app) Details::functionName
. Currently when you bring in the library I am building the bridge for, I already have providers and facades for each of the components. So you register those appropriately.
I have been informed that coupling my library with Laravel like that so tightly is not a good idea. So my questions are simple:
Is this the correct way to write a bridge between a library and laravel? Where the class(es), theres more then one, are registered this way? And will it work as I expect it too?
How do you test this provider? This Bridge package would need to be mocked and I know how to use Mockery, but how would you write effective tests to make sure this acts as expected?