1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Anavel\Crud; |
4
|
|
|
|
5
|
|
|
use Anavel\Crud\Abstractor\Eloquent\FieldFactory as FieldAbstractorFactory; |
6
|
|
|
use Anavel\Crud\Abstractor\Eloquent\ModelFactory as ModelAbstractorFactory; |
7
|
|
|
use Anavel\Crud\Abstractor\Eloquent\RelationFactory as RelationAbstractorFactory; |
8
|
|
|
use Anavel\Crud\Http\Form\Generator as FormGenerator; |
9
|
|
|
use Anavel\Foundation\Support\ModuleProvider; |
10
|
|
|
use FormManager\Factory as FormFactory; |
11
|
|
|
use Request; |
12
|
|
|
use Schema; |
13
|
|
|
|
14
|
|
|
class CrudModuleProvider extends ModuleProvider |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* Indicates if loading of the provider is deferred. |
18
|
|
|
* |
19
|
|
|
* @var bool |
20
|
|
|
*/ |
21
|
|
|
protected $defer = false; |
22
|
|
|
protected static $anavel; |
23
|
|
|
|
24
|
|
|
private function isAnavel() |
25
|
|
|
{ |
26
|
|
|
if (self::$anavel !== null) { |
27
|
|
|
return self::$anavel; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
return self::$anavel = (config('anavel.route_prefix') === Request::segment(1)); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public function boot() |
34
|
|
|
{ |
35
|
|
|
if (!self::isAnavel()) { |
36
|
|
|
return; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
$this->loadViewsFrom(__DIR__.'/../views', 'anavel-crud'); |
40
|
|
|
|
41
|
|
|
$this->loadTranslationsFrom(__DIR__.'/../lang', 'anavel-crud'); |
42
|
|
|
|
43
|
|
|
$this->publishes([__DIR__.'/../public/' => public_path('vendor/anavel-crud/')], 'assets'); |
44
|
|
|
$this->publishes([__DIR__.'/../config/anavel-crud.php' => config_path('anavel-crud.php')], 'config'); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Register the service provider. |
49
|
|
|
* |
50
|
|
|
* @return void |
51
|
|
|
*/ |
52
|
|
|
public function register() |
53
|
|
|
{ |
54
|
|
|
if (!self::isAnavel()) { |
55
|
|
|
return; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
$this->mergeConfigFrom(__DIR__.'/../config/anavel-crud.php', 'anavel-crud'); |
59
|
|
|
|
60
|
|
|
$this->app->register('ANavallaSuiza\Laravel\Database\Manager\ModelManagerServiceProvider'); |
61
|
|
|
|
62
|
|
|
$this->app->bind('Anavel\Crud\Contracts\Abstractor\FieldFactory', function () { |
63
|
|
|
return new FieldAbstractorFactory(new FormFactory()); |
64
|
|
|
}); |
65
|
|
|
|
66
|
|
|
$this->app->bind('Anavel\Crud\Contracts\Abstractor\RelationFactory', function () { |
67
|
|
|
return new RelationAbstractorFactory( |
68
|
|
|
$this->app['ANavallaSuiza\Laravel\Database\Contracts\Manager\ModelManager'], |
69
|
|
|
$this->app['Anavel\Crud\Contracts\Abstractor\FieldFactory'] |
70
|
|
|
); |
71
|
|
|
}); |
72
|
|
|
|
73
|
|
|
$this->app->bind('Anavel\Crud\Contracts\Abstractor\ModelFactory', function () { |
74
|
|
|
return new ModelAbstractorFactory( |
75
|
|
|
config('anavel-crud.models'), |
76
|
|
|
$this->app['ANavallaSuiza\Laravel\Database\Contracts\Manager\ModelManager'], |
77
|
|
|
$this->app['Anavel\Crud\Contracts\Abstractor\RelationFactory'], |
78
|
|
|
$this->app['Anavel\Crud\Contracts\Abstractor\FieldFactory'], |
79
|
|
|
$this->app['Anavel\Crud\Contracts\Form\Generator'], |
80
|
|
|
$this->app['Anavel\Foundation\Contracts\Anavel'] |
81
|
|
|
); |
82
|
|
|
}); |
83
|
|
|
|
84
|
|
|
$this->app->bind('Anavel\Crud\Contracts\Form\Generator', function () { |
85
|
|
|
return new FormGenerator(new FormFactory()); |
86
|
|
|
}); |
87
|
|
|
|
88
|
|
|
$this->app->register('Anavel\Crud\Providers\ViewComposersServiceProvider'); |
89
|
|
|
|
90
|
|
|
$this->registerDoctrineTypeMappings(); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* Get the services provided by the provider. |
95
|
|
|
* |
96
|
|
|
* @return array |
97
|
|
|
*/ |
98
|
|
|
public function provides() |
99
|
|
|
{ |
100
|
|
|
return []; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
public function name() |
104
|
|
|
{ |
105
|
|
|
return config('anavel-crud.name'); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
public function routes() |
109
|
|
|
{ |
110
|
|
|
return __DIR__.'/Http/routes.php'; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
public function mainRoute() |
114
|
|
|
{ |
115
|
|
|
return route('anavel-crud.home'); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
public function hasSidebar() |
119
|
|
|
{ |
120
|
|
|
return true; |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
public function sidebarMenu() |
124
|
|
|
{ |
125
|
|
|
return 'anavel-crud::molecules.sidebar.default'; |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
public function isActive() |
129
|
|
|
{ |
130
|
|
|
return self::isAnavel() && (strpos(Request::route()->uri(), 'crud') !== false); |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* Registers types that Doctrine doesn's support by default. |
135
|
|
|
*/ |
136
|
|
|
protected function registerDoctrineTypeMappings() |
137
|
|
|
{ |
138
|
|
|
Schema::getConnection() |
139
|
|
|
->getDoctrineConnection() |
140
|
|
|
->getDatabasePlatform() |
141
|
|
|
->registerDoctrineTypeMapping('enum', 'string'); |
142
|
|
|
} |
143
|
|
|
} |
144
|
|
|
|