Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
100.00% |
1 / 1 |
|
100.00% |
5 / 5 |
CRAP | |
100.00% |
27 / 27 |
| ShopServiceProvider | |
100.00% |
1 / 1 |
|
100.00% |
6 / 6 |
11 | |
100.00% |
27 / 27 |
| boot | |
100.00% |
1 / 1 |
1 | |
100.00% |
3 / 3 |
|||
| register | |
100.00% |
1 / 1 |
3 | |
100.00% |
12 / 12 |
|||
| anonymous function | |
100.00% |
1 / 1 |
2 | |
100.00% |
4 / 4 |
|||
| defineRoutes | |
100.00% |
1 / 1 |
3 | |
100.00% |
4 / 4 |
|||
| defineRouteBindings | |
100.00% |
1 / 1 |
1 | |
100.00% |
0 / 0 |
|||
| defineResources | |
100.00% |
1 / 1 |
1 | |
100.00% |
3 / 3 |
|||
| <?php | |
| namespace Mtc\Shop\Providers; | |
| use Event; | |
| use Illuminate\Support\Facades\Auth; | |
| use Illuminate\Support\Facades\Route; | |
| use Illuminate\Support\ServiceProvider; | |
| use Mtc\Shop\Basket; | |
| use Mtc\Shop\Contracts\BasketContract; | |
| use Mtc\Shop\Contracts\ProductRepositoryContract; | |
| use Mtc\Shop\Http\ViewComposers\BasketComposer; | |
| use Mtc\Shop\Product; | |
| use Mtc\Shop\Repositories\ProductRepository; | |
| use Mtc\Shop\Variant; | |
| use View; | |
| class ShopServiceProvider extends ServiceProvider | |
| { | |
| /** | |
| * Boot the service provider. | |
| * | |
| * @return void | |
| */ | |
| public function boot() | |
| { | |
| $this->defineResources(); | |
| $this->defineRoutes(); | |
| } | |
| /** | |
| * Register the service provider. | |
| * | |
| * @return void | |
| */ | |
| public function register() | |
| { | |
| if (! defined('SHOP_PATH')) { | |
| define('SHOP_PATH', realpath(__DIR__.'/../../')); | |
| } | |
| $this->app->bind(ProductRepositoryContract::class, ProductRepository::class); | |
| // Load a custom basket (or default). | |
| $this->app->singleton(BasketContract::class, function($app) { | |
| $class = config('shop.model', Basket::class); | |
| return $class::findOrNew(session('basket_id')); | |
| }); | |
| // Register the singleton class to the necessary views | |
| View::composer( | |
| [ | |
| 'theme::layouts.*', | |
| ], | |
| BasketComposer::class | |
| ); | |
| if ($this->app->runningInConsole()) { | |
| $this->commands([]); | |
| } | |
| } | |
| /** | |
| * Define the routes. | |
| * | |
| * @return void | |
| */ | |
| protected function defineRoutes() | |
| { | |
| $this->defineRouteBindings(); | |
| /** | |
| * If the routes have not been cached, we will include them in a route group | |
| * so that all of the routes will be conveniently registered to the given | |
| * controller namespace. After that we will load the Core routes file. | |
| */ | |
| if (! $this->app->routesAreCached()) { | |
| Route::group( | |
| ['namespace' => 'Mtc\Shop\Http\Controllers'], | |
| function ($router) { | |
| $path = realpath(SHOP_PATH . '/routes'); | |
| foreach (glob("{$path}/*.php") as $file) { | |
| require $file; | |
| } | |
| } | |
| ); | |
| } | |
| } | |
| /** | |
| * Define the route model bindings. | |
| * | |
| * @return void | |
| */ | |
| protected function defineRouteBindings() {} | |
| /** | |
| * Define the resources for this package. | |
| * | |
| * @return void | |
| */ | |
| protected function defineResources() | |
| { | |
| $this->loadViewsFrom(SHOP_PATH . '/resources/views', 'shop'); | |
| $this->loadTranslationsFrom(SHOP_PATH . '/resources/lang', 'shop'); | |
| } | |
| } |