|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Distilleries\FormBuilder; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Foundation\AliasLoader; |
|
6
|
|
|
use Kris\LaravelFormBuilder\FormHelper; |
|
7
|
|
|
use Kris\LaravelFormBuilder\FormBuilder; |
|
8
|
|
|
use Collective\Html\FormBuilder as LaravelForm; |
|
9
|
|
|
use Collective\Html\HtmlBuilder as LaravelHtml; |
|
10
|
|
|
use Kris\LaravelFormBuilder\FormBuilderServiceProvider as BaseFormBuilderServiceProvider; |
|
11
|
|
|
|
|
12
|
|
|
class FormBuilderServiceProvider extends BaseFormBuilderServiceProvider |
|
13
|
|
|
{ |
|
14
|
|
|
public function boot() |
|
15
|
|
|
{ |
|
16
|
164 |
|
parent::boot(); |
|
17
|
|
|
|
|
18
|
164 |
|
$this->loadViewsFrom(__DIR__ . '/../../views', 'form-builder'); |
|
19
|
|
|
$this->loadTranslationsFrom(__DIR__ . '/../../lang', 'form-builder'); |
|
20
|
164 |
|
|
|
21
|
164 |
|
$this->publishes([__DIR__ . '/../../config/config.php' => config_path('form-builder.php')]); |
|
22
|
|
|
$this->publishes([__DIR__ . '/../../views' => base_path('resources/views/vendor/form-builder')], 'views'); |
|
23
|
164 |
|
|
|
24
|
164 |
|
$this->mergeConfigFrom(__DIR__ . '/../../config/config.php', 'form-builder'); |
|
25
|
|
|
} |
|
26
|
164 |
|
|
|
27
|
|
|
public function register() |
|
28
|
164 |
|
{ |
|
29
|
|
|
$this->commands(\Kris\LaravelFormBuilder\Console\FormMakeCommand::class); |
|
30
|
|
|
|
|
31
|
|
|
$this->registerHtmlIfNeeded(); |
|
32
|
64 |
|
$this->registerFormIfHeeded(); |
|
33
|
164 |
|
|
|
34
|
|
|
$this->mergeConfigFrom(__DIR__ . '/../../config/config.php', 'laravel-form-builder'); |
|
35
|
164 |
|
|
|
36
|
|
|
$this->registerFormHelper(); |
|
37
|
164 |
|
|
|
38
|
164 |
|
$this->app->singleton('laravel-form-builder', function ($app) { |
|
39
|
|
|
return new FormBuilder($app, $app['laravel-form-helper']); |
|
40
|
164 |
|
}); |
|
41
|
|
|
|
|
42
|
|
|
$this->commands(\Distilleries\FormBuilder\Console\FormMakeCommand::class); |
|
43
|
|
|
|
|
44
|
|
|
$this->alias(); |
|
45
|
144 |
|
} |
|
46
|
|
|
|
|
47
|
144 |
|
protected function registerFormHelper() |
|
48
|
164 |
|
{ |
|
49
|
|
|
$this->app->singleton('laravel-form-helper', function ($app) { |
|
50
|
164 |
|
$config = $app['config']->get('form-builder'); |
|
51
|
164 |
|
return new FormHelper($app['view'], $app['request'], $config); |
|
52
|
|
|
}); |
|
53
|
|
|
|
|
54
|
164 |
|
$this->app->alias('laravel-form-helper', 'Kris\LaravelFormBuilder\FormHelper'); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
164 |
|
private function registerHtmlIfNeeded() |
|
|
|
|
|
|
58
|
|
|
{ |
|
59
|
164 |
|
if (! $this->app->offsetExists('html')) { |
|
60
|
164 |
|
$this->app->singleton('html', function ($app) { |
|
61
|
|
|
return new LaravelHtml($app['url'], $app['view']); |
|
62
|
164 |
|
}); |
|
63
|
164 |
|
|
|
64
|
164 |
|
$this->registerAliasIfNotExists('Html', \Collective\Html\HtmlFacade::class); |
|
65
|
164 |
|
} |
|
66
|
164 |
|
} |
|
67
|
164 |
|
|
|
68
|
|
|
private function registerFormIfHeeded() |
|
|
|
|
|
|
69
|
|
|
{ |
|
70
|
164 |
|
if (! $this->app->offsetExists('form')) { |
|
71
|
164 |
|
$this->app->singleton('form', function ($app) { |
|
72
|
|
|
$form = new LaravelForm($app['html'], $app['url'], $app['view'], $app['session.store']->getToken()); |
|
73
|
164 |
|
return $form->setSessionStore($app['session.store']); |
|
74
|
164 |
|
}); |
|
75
|
|
|
|
|
76
|
|
|
$this->registerAliasIfNotExists('Form', \Collective\Html\FormFacade::class); |
|
77
|
|
|
} |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
164 |
|
private function alias() |
|
81
|
|
|
{ |
|
82
|
164 |
|
$this->registerAliasIfNotExists('FormBuilder', Facades\FormBuilder::class); |
|
83
|
|
|
$this->registerAliasIfNotExists('Request', \Illuminate\Support\Facades\Request::class); |
|
84
|
|
|
$this->registerAliasIfNotExists('Route', \Illuminate\Support\Facades\Route::class); |
|
85
|
|
|
$this->registerAliasIfNotExists('File', \Illuminate\Support\Facades\File::class); |
|
86
|
84 |
|
$this->registerAliasIfNotExists('Redirect', \Illuminate\Support\Facades\Redirect::class); |
|
87
|
|
|
} |
|
88
|
84 |
|
|
|
89
|
164 |
|
private function registerAliasIfNotExists($alias, $class) |
|
90
|
|
|
{ |
|
91
|
164 |
|
if (! array_key_exists($alias, AliasLoader::getInstance()->getAliases())) { |
|
92
|
|
|
AliasLoader::getInstance()->alias($alias, $class); |
|
93
|
4 |
|
} |
|
94
|
4 |
|
} |
|
95
|
|
|
} |
|
96
|
|
|
|
Overwriting private methods is generally fine as long as you also use private visibility. It might still be preferable for understandability to use a different method name.