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

TranslatableBootFormsServiceProvider::getLocales()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
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