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([ |
44
|
|
|
__DIR__.'/../public/' => public_path('vendor/anavel-crud/'), |
45
|
|
|
], 'assets'); |
46
|
|
|
|
47
|
|
|
$this->publishes([ |
48
|
|
|
__DIR__.'/../config/anavel-crud.php' => config_path('anavel-crud.php'), |
49
|
|
|
], 'config'); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Register the service provider. |
54
|
|
|
* |
55
|
|
|
* @return void |
56
|
|
|
*/ |
57
|
|
|
public function register() |
58
|
|
|
{ |
59
|
|
|
if (!self::isAnavel()) { |
60
|
|
|
return; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
$this->mergeConfigFrom(__DIR__.'/../config/anavel-crud.php', 'anavel-crud'); |
64
|
|
|
|
65
|
|
|
$this->app->register('ANavallaSuiza\Laravel\Database\Manager\ModelManagerServiceProvider'); |
66
|
|
|
|
67
|
|
|
$this->app->bind( |
68
|
|
|
'Anavel\Crud\Contracts\Abstractor\FieldFactory', |
69
|
|
|
function () { |
70
|
|
|
return new FieldAbstractorFactory(new FormFactory()); |
71
|
|
|
} |
72
|
|
|
); |
73
|
|
|
|
74
|
|
|
$this->app->bind( |
75
|
|
|
'Anavel\Crud\Contracts\Abstractor\RelationFactory', |
76
|
|
|
function () { |
77
|
|
|
return new RelationAbstractorFactory( |
78
|
|
|
$this->app['ANavallaSuiza\Laravel\Database\Contracts\Manager\ModelManager'], |
79
|
|
|
$this->app['Anavel\Crud\Contracts\Abstractor\FieldFactory'] |
80
|
|
|
); |
81
|
|
|
} |
82
|
|
|
); |
83
|
|
|
|
84
|
|
|
$this->app->bind( |
85
|
|
|
'Anavel\Crud\Contracts\Abstractor\ModelFactory', |
86
|
|
|
function () { |
87
|
|
|
return new ModelAbstractorFactory( |
88
|
|
|
config('anavel-crud.models'), |
89
|
|
|
$this->app['ANavallaSuiza\Laravel\Database\Contracts\Manager\ModelManager'], |
90
|
|
|
$this->app['Anavel\Crud\Contracts\Abstractor\RelationFactory'], |
91
|
|
|
$this->app['Anavel\Crud\Contracts\Abstractor\FieldFactory'], |
92
|
|
|
$this->app['Anavel\Crud\Contracts\Form\Generator'], |
93
|
|
|
$this->app['Anavel\Foundation\Contracts\Anavel'] |
94
|
|
|
); |
95
|
|
|
} |
96
|
|
|
); |
97
|
|
|
|
98
|
|
|
$this->app->bind( |
99
|
|
|
'Anavel\Crud\Contracts\Form\Generator', |
100
|
|
|
function () { |
101
|
|
|
return new FormGenerator(new FormFactory()); |
102
|
|
|
} |
103
|
|
|
); |
104
|
|
|
|
105
|
|
|
$this->app->register('Anavel\Crud\Providers\ViewComposersServiceProvider'); |
106
|
|
|
|
107
|
|
|
$this->registerDoctrineTypeMappings(); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* Get the services provided by the provider. |
112
|
|
|
* |
113
|
|
|
* @return array |
114
|
|
|
*/ |
115
|
|
|
public function provides() |
116
|
|
|
{ |
117
|
|
|
return []; |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
public function name() |
121
|
|
|
{ |
122
|
|
|
return config('anavel-crud.name'); |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
public function routes() |
126
|
|
|
{ |
127
|
|
|
return __DIR__.'/Http/routes.php'; |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
public function mainRoute() |
131
|
|
|
{ |
132
|
|
|
return route('anavel-crud.home'); |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
public function hasSidebar() |
136
|
|
|
{ |
137
|
|
|
return true; |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
public function sidebarMenu() |
141
|
|
|
{ |
142
|
|
|
return 'anavel-crud::molecules.sidebar.default'; |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
public function isActive() |
146
|
|
|
{ |
147
|
|
|
$uri = Request::route()->uri(); |
148
|
|
|
|
149
|
|
|
return self::isAnavel() && (strpos($uri, 'crud') !== false); |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
/** |
153
|
|
|
* Registers types that Doctrine doesn's support by default. |
154
|
|
|
*/ |
155
|
|
|
protected function registerDoctrineTypeMappings() |
156
|
|
|
{ |
157
|
|
|
$connection = Schema::getConnection(); |
158
|
|
|
$platform = $connection->getDoctrineConnection()->getDatabasePlatform(); |
159
|
|
|
|
160
|
|
|
$platform->registerDoctrineTypeMapping('enum', 'string'); |
161
|
|
|
} |
162
|
|
|
} |
163
|
|
|
|