Completed
Push — devops/catch-breaking-changes-... ( 88c9a6 )
by Bas
28s queued 18s
created

AranguentServiceProvider::boot()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 5
ccs 3
cts 3
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace LaravelFreelancerNL\Aranguent;
4
5
use Illuminate\Support\ServiceProvider;
6
use LaravelFreelancerNL\Aranguent\Eloquent\Model;
7
use Illuminate\Database\Migrations\MigrationCreator as IlluminateMigrationCreator;
8
use LaravelFreelancerNL\Aranguent\Migrations\MigrationCreator;
9
use LaravelFreelancerNL\Aranguent\Schema\Grammar as SchemaGrammar;
10
11
class AranguentServiceProvider extends ServiceProvider
12
{
13
    /**
14
     * Components to register on the provider.
15
     *
16
     * @var array
17
     */
18
    protected $components = [
19
        'Migration',
20
    ];
21
22
    /**
23
     * Bootstrap services.
24
     *
25
     * @return void
26
     */
27 207
    public function boot()
28
    {
29 207
        Model::setConnectionResolver($this->app['db']);
30
31 207
        Model::setEventDispatcher($this->app['events']);
32
    }
33
34
    /**
35
     * Register services.
36
     *
37
     * @return void
38
     */
39 207
    public function register()
40
    {
41
        /**
42
         * When the MigrationCreator complains about an unset $customStubPath
43
         * we resolve it here
44
         */
45 207
        $this->app->when(MigrationCreator::class)
46
            ->needs('$customStubPath')
47 207
            ->give(function () {
48 207
                return __DIR__ . '/../stubs';
49
            });
50 207
        $this->app->when(IlluminateMigrationCreator::class)
51
            ->needs('$customStubPath')
52 207
            ->give(function () {
53
                return __DIR__ . '/../stubs';
54
            });
55
56 207
        $this->app->resolving(
57
            'db',
58 207
            function ($db) {
59 207
                $db->extend(
60
                    'arangodb',
61 207
                    function ($config, $name) {
62 207
                        $config['name'] = $name;
63 207
                        $connection = new Connection($config);
64 207
                        $connection->setSchemaGrammar(new SchemaGrammar());
65
66 207
                        return $connection;
67
                    }
68
                );
69
            }
70
        );
71
72 207
        $this->app->resolving(
73 207
            function () {
74 207
                if (class_exists('Illuminate\Foundation\AliasLoader')) {
75 207
                    $loader = \Illuminate\Foundation\AliasLoader::getInstance();
76 207
                    $loader->alias('Eloquent', 'LaravelFreelancerNL\Aranguent\Eloquent\Model');
77
                }
78
            }
79
        );
80
81 207
        $this->app->register('LaravelFreelancerNL\Aranguent\Providers\CommandServiceProvider');
82
    }
83
}
84