Completed
Push — master ( 2b0ce8...94c7b3 )
by ARCANEDEV
8s
created

RedirectorManager::config()   A

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
     * Get the default driver name.
20
     *
21
     * @return string
22
     */
23 27
    public function getDefaultDriver()
24
    {
25 27
        return $this->config()->get('seo.redirector.default', 'config');
26
    }
27
28
    /**
29
     * Get the config repository.
30
     *
31
     * @return \Illuminate\Contracts\Config\Repository
32
     */
33 33
    protected function config()
34
    {
35 33
        return $this->app['config'];
36
    }
37
38
    /* -----------------------------------------------------------------
39
     |  Main Methods
40
     | -----------------------------------------------------------------
41
     */
42
    /* -----------------------------------------------------------------
43
     |  Main Methods
44
     | -----------------------------------------------------------------
45
     */
46
    /**
47
     * Get a driver instance.
48
     *
49
     * @param  string  $driver
50
     *
51
     * @return \Arcanedev\LaravelSeo\Contracts\Redirector
52
     */
53 30
    public function driver($driver = null)
54
    {
55 30
        return parent::driver($driver);
56
    }
57
58
    /**
59
     * Build the config redirector driver.
60
     *
61
     * @return \Arcanedev\LaravelSeo\Redirectors\ConfigurationRedirector
62
     */
63 27
    public function createConfigDriver()
64
    {
65 27
        return $this->buildDriver('config');
66
    }
67
68
    /**
69
     * Build the eloquent redirector driver.
70
     *
71
     * @return \Arcanedev\LaravelSeo\Redirectors\EloquentRedirector
72
     */
73 3
    public function createEloquentDriver()
74
    {
75 3
        return $this->buildDriver('eloquent');
76
    }
77
78
    /* -----------------------------------------------------------------
79
     |  Other Methods
80
     | -----------------------------------------------------------------
81
     */
82
    /**
83
     * Build the redirector.
84
     *
85
     * @param  string  $driver
86
     *
87
     * @return \Arcanedev\LaravelSeo\Contracts\Redirector
88
     */
89 30
    private function buildDriver($driver)
90
    {
91 30
        $router  = $this->app->make(\Illuminate\Contracts\Routing\Registrar::class);
92 30
        $class   = $this->config()->get("seo.redirector.drivers.$driver.class");
93 30
        $options = $this->config()->get("seo.redirector.drivers.$driver.options", []);
94
95 30
        return new $class($router, $options);
96
    }
97
}
98