RedirectorManager::getDefaultDriver()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php namespace Arcanedev\LaravelSeo;
2
3
use Arcanedev\LaravelSeo\Contracts\RedirectorFactory;
4
use Illuminate\Support\Manager;
5
6
/**
7
 * Class     RedirectorManager
8
 *
9
 * @package  Arcanedev\LaravelSeo
10
 * @author   ARCANEDEV <[email protected]>
11
 */
12
class RedirectorManager extends Manager implements RedirectorFactory
13
{
14
    /* -----------------------------------------------------------------
15
     |  Getters & Setters
16
     | -----------------------------------------------------------------
17
     */
18
19
    /**
20
     * Get the default driver name.
21
     *
22
     * @return string
23
     */
24 18
    public function getDefaultDriver()
25
    {
26 18
        return Seo::getConfig('redirector.default', 'config');
27
    }
28
29
    /* -----------------------------------------------------------------
30
     |  Main Methods
31
     | -----------------------------------------------------------------
32
     */
33
34
    /**
35
     * Get a driver instance.
36
     *
37
     * @param  string  $driver
38
     *
39
     * @return \Arcanedev\LaravelSeo\Contracts\Redirector
40
     */
41 20
    public function driver($driver = null)
42
    {
43 20
        return parent::driver($driver);
44
    }
45
46
    /**
47
     * Build the config redirector driver.
48
     *
49
     * @return \Arcanedev\LaravelSeo\Redirectors\ConfigurationRedirector
50
     */
51 18
    public function createConfigDriver()
52
    {
53 18
        return $this->buildDriver('config');
54
    }
55
56
    /**
57
     * Build the eloquent redirector driver.
58
     *
59
     * @return \Arcanedev\LaravelSeo\Redirectors\EloquentRedirector
60
     */
61 2
    public function createEloquentDriver()
62
    {
63 2
        return $this->buildDriver('eloquent', [
64 2
            'model' => Seo::getConfig('redirects.model'),
65
        ]);
66
    }
67
68
    /* -----------------------------------------------------------------
69
     |  Other Methods
70
     | -----------------------------------------------------------------
71
     */
72
73
    /**
74
     * Build the redirector.
75
     *
76
     * @param  string  $driver
77
     * @param  array   $extra
78
     *
79
     * @return mixed
80
     */
81 20
    private function buildDriver($driver, array $extra = [])
82
    {
83 20
        $router  = $this->app->make(\Illuminate\Contracts\Routing\Registrar::class);
84 20
        $class   = Seo::getConfig("redirector.drivers.$driver.class");
85 20
        $options = Seo::getConfig("redirector.drivers.$driver.options", []);
86
87 20
        return new $class($router, array_merge($extra, $options));
88
    }
89
}
90