Completed
Push — master ( 97eec8...f7e54d )
by Propa
02:53
created

TranslatableBootFormsServiceProvider   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 77
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 7
Bugs 2 Features 0
Metric Value
wmc 4
c 7
b 2
f 0
lcom 1
cbo 4
dl 0
loc 77
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 6 1
B register() 0 26 1
A provides() 0 7 1
A getLocales() 0 4 1
1
<?php namespace Propaganistas\LaravelTranslatableBootForms;
2
3
use Illuminate\Support\ServiceProvider;
4
5
class TranslatableBootFormsServiceProvider extends ServiceProvider {
6
7
    /**
8
     * Indicates if loading of the provider is deferred.
9
     *
10
     * @var bool
11
     */
12
    protected $defer = true;
13
14
    /**
15
     * Boot the application events.
16
     *
17
     * @return void
18
     */
19
    public function boot()
20
    {
21
        $this->publishes([
22
            __DIR__.'/../config/config.php' => config_path('translatable-bootforms.php'),
23
        ], 'config');
24
    }
25
26
    /**
27
     * Register the service provider.
28
     *
29
     * @return void
30
     */
31
    public function register()
32
    {
33
        $this->mergeConfigFrom(
34
            __DIR__.'/../config/config.php', 'translatable-bootforms'
35
        );
36
37
        // Override BootForm's form builder in order to get model binding
38
        // between BootForm & TranslatableBootForm working.
39
        $this->app['adamwathan.form'] = $this->app->share(function ($app) {
40
            $formBuilder = new Form\FormBuilder();
41
            $formBuilder->setLocales($this->getLocales());
42
            $formBuilder->setErrorStore($app['adamwathan.form.errorstore']);
43
            $formBuilder->setOldInputProvider($app['adamwathan.form.oldinput']);
44
            $formBuilder->setToken($app['session.store']->getToken());
45
46
            return $formBuilder;
47
        });
48
49
        // Define TranslatableBootForm.
50
        $this->app['translatable-bootform'] = $this->app->share(function ($app) {
51
            $form = new TranslatableBootForm($app['bootform']);
52
            $form->locales($this->getLocales());
53
54
            return $form;
55
        });
56
    }
57
58
    /**
59
     * Get the services provided by the provider.
60
     *
61
     * @return array
62
     */
63
    public function provides()
64
    {
65
        return array(
66
            'adamwathan.form',
67
            'translatable-bootform',
68
        );
69
    }
70
    
71
    /**
72
     * Get Translatable's locales.
73
     * 
74
     * @return array
75
     */
76
    protected function getLocales()
77
    {
78
        return with(new Translatable\TranslatableWrapper)->getLocales();
79
    }
80
81
}
82