Skip to content

Commit 9140e27

Browse files
committed
cleans up the publishable service provider
1 parent 38cdec1 commit 9140e27

File tree

2 files changed

+116
-86
lines changed

2 files changed

+116
-86
lines changed
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
<?php
2+
3+
namespace vicgonvt\LaraPress;
4+
5+
use Illuminate\Support\Facades\Route;
6+
use Illuminate\Support\ServiceProvider;
7+
8+
class LaraPressBaseServiceProvider extends ServiceProvider
9+
{
10+
/**
11+
* Bootstrap any package services.
12+
*
13+
* @return void
14+
*/
15+
public function boot()
16+
{
17+
if ($this->app->runningInConsole()) {
18+
$this->registerPublishing();
19+
}
20+
21+
$this->registerResources();
22+
}
23+
24+
/**
25+
* Register the package resources such as routes, templates, etc.
26+
*
27+
* @return void
28+
*/
29+
protected function registerResources()
30+
{
31+
$this->loadViewsFrom(__DIR__.'/../resources/views', 'larapress');
32+
$this->loadMigrationsFrom(__DIR__.'/../database/migrations');
33+
34+
$this->registerRoutes();
35+
$this->registerHelpers();
36+
$this->registerFacades();
37+
}
38+
39+
/**
40+
* Register the package's publishable resources.
41+
*
42+
* @return void
43+
*/
44+
protected function registerPublishing()
45+
{
46+
$this->publishes([
47+
__DIR__.'/LaraPressServiceProvider.php' => app_path('Providers/LaraPressServiceProvider.php'),
48+
], 'larapress-provider');
49+
$this->publishes([
50+
__DIR__.'/../config/larapress.php' => config_path('larapress.php'),
51+
], 'larapress-config');
52+
}
53+
54+
/**
55+
* Register the package routes.
56+
*
57+
* @return void
58+
*/
59+
protected function registerRoutes()
60+
{
61+
Route::group($this->routeConfiguration(), function () {
62+
$this->loadRoutesFrom(__DIR__.'/../routes/web.php');
63+
});
64+
}
65+
66+
/**
67+
* Register the additional helpers needed.
68+
*/
69+
protected function registerHelpers()
70+
{
71+
if (file_exists($file = __DIR__.'/Helpers/helpers.php')) {
72+
require $file;
73+
}
74+
}
75+
76+
/**
77+
* Register any bindings to the app.
78+
*/
79+
protected function registerFacades()
80+
{
81+
$this->app->singleton('LaraPress', function ($app) {
82+
return new LaraPress();
83+
});
84+
}
85+
86+
/**
87+
* Get the LaraPress route group configuration array.
88+
*
89+
* @return array
90+
*/
91+
protected function routeConfiguration()
92+
{
93+
return [
94+
'namespace' => 'vicgonvt\LaraPress\Http\Controllers',
95+
'prefix' => LaraPress::path(),
96+
];
97+
}
98+
99+
/**
100+
* Register any application services.
101+
*
102+
* @return void
103+
*/
104+
public function register()
105+
{
106+
$this->commands([
107+
Console\ProcessCommand::class,
108+
]);
109+
}
110+
}

src/LaraPressServiceProvider.php

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

33
namespace vicgonvt\LaraPress;
44

5-
use Illuminate\Support\Facades\Route;
6-
use Illuminate\Support\ServiceProvider;
7-
8-
class LaraPressServiceProvider extends ServiceProvider
5+
class LaraPressServiceProvider extends LaraPressBaseServiceProvider
96
{
107
/**
118
* Bootstrap any package services.
@@ -14,86 +11,9 @@ class LaraPressServiceProvider extends ServiceProvider
1411
*/
1512
public function boot()
1613
{
17-
if ($this->app->runningInConsole()) {
18-
$this->registerPublishing();
19-
}
20-
21-
$this->registerResources();
22-
}
23-
24-
/**
25-
* Register the package resources such as routes, templates, etc.
26-
*
27-
* @return void
28-
*/
29-
protected function registerResources()
30-
{
31-
$this->loadViewsFrom(__DIR__.'/../resources/views', 'larapress');
32-
$this->loadMigrationsFrom(__DIR__.'/../database/migrations');
33-
34-
$this->registerRoutes();
35-
$this->registerHelpers();
36-
$this->registerFacades();
37-
}
38-
39-
/**
40-
* Register the package's publishable resources.
41-
*
42-
* @return void
43-
*/
44-
protected function registerPublishing()
45-
{
46-
$this->publishes([
47-
__DIR__.'/LaraPressServiceProvider.php' => app_path('Providers/LaraPressServiceProvider.php'),
48-
], 'larapress-provider');
49-
$this->publishes([
50-
__DIR__.'/../config/larapress.php' => config_path('larapress.php'),
51-
], 'larapress-config');
52-
}
53-
54-
/**
55-
* Register the package routes.
56-
*
57-
* @return void
58-
*/
59-
protected function registerRoutes()
60-
{
61-
Route::group($this->routeConfiguration(), function () {
62-
$this->loadRoutesFrom(__DIR__.'/../routes/web.php');
63-
});
64-
}
65-
66-
/**
67-
* Register the additional helpers needed.
68-
*/
69-
protected function registerHelpers()
70-
{
71-
if (file_exists($file = __DIR__.'/Helpers/helpers.php')) {
72-
require $file;
73-
}
74-
}
75-
76-
/**
77-
* Register any bindings to the app.
78-
*/
79-
protected function registerFacades()
80-
{
81-
$this->app->singleton('LaraPress', function ($app) {
82-
return new LaraPress();
83-
});
84-
}
14+
parent::boot();
8515

86-
/**
87-
* Get the LaraPress route group configuration array.
88-
*
89-
* @return array
90-
*/
91-
protected function routeConfiguration()
92-
{
93-
return [
94-
'namespace' => 'vicgonvt\LaraPress\Http\Controllers',
95-
'prefix' => LaraPress::path(),
96-
];
16+
//
9717
}
9818

9919
/**
@@ -103,8 +23,8 @@ protected function routeConfiguration()
10323
*/
10424
public function register()
10525
{
106-
$this->commands([
107-
Console\ProcessCommand::class,
108-
]);
26+
parent::register();
27+
28+
//
10929
}
11030
}

0 commit comments

Comments
 (0)