forked from crocodic-studio/crudbooster
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCRUDBoosterServiceProvider.php
125 lines (104 loc) · 4.51 KB
/
CRUDBoosterServiceProvider.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<?php namespace crocodicstudio\crudbooster;
use crocodicstudio\crudbooster\commands\CrudboosterVersionCommand;
use crocodicstudio\crudbooster\commands\Mailqueues;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\ServiceProvider;
use crocodicstudio\crudbooster\commands\CrudboosterInstallationCommand;
use crocodicstudio\crudbooster\commands\CrudboosterUpdateCommand;
use Illuminate\Foundation\AliasLoader;
use App;
class CRUDBoosterServiceProvider extends ServiceProvider
{
/**
* Bootstrap the application services.
* Call when after all packages has been loaded
*
* @return void
*/
public function boot()
{
$this->loadViewsFrom(__DIR__.'/views', 'crudbooster');
$this->loadMigrationsFrom(__DIR__.'/database/migrations');
$this->loadTranslationsFrom(__DIR__.'/localization','crudbooster');
$this->loadRoutesFrom(__DIR__.'/routes.php');
if($this->app->runningInConsole()) {
$this->registerSeedsFrom(__DIR__.'/database/seeds');
$this->publishes([__DIR__.'/configs/crudbooster.php' => config_path('crudbooster.php')],'cb_config');
$this->publishes([__DIR__.'/userfiles/controllers/CBHook.php' => app_path('Http/Controllers/CBHook.php')],'CBHook');
$this->publishes([__DIR__.'/userfiles/controllers/AdminCmsUsersController.php' => app_path('Http/Controllers/AdminCmsUsersController.php')],'cb_user_controller');
$this->publishes([__DIR__.'/assets'=>public_path('vendor/crudbooster')],'cb_asset');
}
$this->customValidation();
}
/**
* Register the application services.
* Call when this package is first time loaded
*
* @return void
*/
public function register()
{
require __DIR__.'/helpers/Helper.php';
$this->mergeConfigFrom(__DIR__.'/configs/crudbooster.php','crudbooster');
$this->registerSingleton();
if($this->app->runningInConsole()) {
$this->commands('crudboosterinstall');
$this->commands('crudboosterupdate');
$this->commands('crudboosterVersionCommand');
$this->commands('crudboosterMailQueue');
}
$loader = AliasLoader::getInstance();
$loader->alias('PDF', 'Barryvdh\DomPDF\Facade');
$loader->alias('Excel', 'Maatwebsite\Excel\Facades\Excel');
$loader->alias('Image', 'Intervention\Image\ImageManagerStatic');
$loader->alias('CRUDBooster', 'crocodicstudio\crudbooster\helpers\CRUDBooster');
$loader->alias('CB', 'crocodicstudio\crudbooster\helpers\CB');
}
private function registerSingleton()
{
$this->app->singleton('crudbooster', function ()
{
return true;
});
$this->app->singleton('crudboosterinstall',function() {
return new CrudboosterInstallationCommand;
});
$this->app->singleton('crudboosterupdate',function() {
return new CrudboosterUpdateCommand;
});
$this->app->singleton("crudboosterVersionCommand", function() {
return new CrudboosterVersionCommand;
});
$this->app->singleton("crudboosterMailQueue", function() {
return new Mailqueues;
});
}
protected function registerSeedsFrom($path)
{
foreach (glob("$path/*.php") as $filename)
{
include $filename;
$classes = get_declared_classes();
$class = end($classes);
$command = request()->server('argv', null);
if (is_array($command)) {
$command = implode(' ', $command);
if ($command == "artisan db:seed") {
Artisan::call('db:seed', ['--class' => $class]);
}
}
}
}
private function customValidation() {
Validator::extend('alpha_spaces', function ($attribute, $value) {
// This will only accept alpha and spaces.
// If you want to accept hyphens use: /^[\pL\s-]+$/u.
return preg_match('/^[\pL\s]+$/u', $value);
},'The :attribute should be letters and spaces only');
Validator::extend('alpha_num_spaces', function ($attribute, $value) {
// This will only accept alphanumeric and spaces.
return preg_match('/^[a-zA-Z0-9\s]+$/', $value);
},'The :attribute should be alphanumeric characters and spaces only');
}
}