Completed
Push — master ( 0ecaab...d43f4a )
by ARCANEDEV
04:16
created

RedirectorManager::driver()   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 1
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 Seo::getConfig('redirector.default', 'config');
26
    }
27
28
    /* -----------------------------------------------------------------
29
     |  Main Methods
30
     | -----------------------------------------------------------------
31
     */
32
    /**
33
     * Get a driver instance.
34
     *
35
     * @param  string  $driver
36
     *
37
     * @return \Arcanedev\LaravelSeo\Contracts\Redirector
38
     */
39 30
    public function driver($driver = null)
40
    {
41 30
        return parent::driver($driver);
42
    }
43
44
    /**
45
     * Build the config redirector driver.
46
     *
47
     * @return \Arcanedev\LaravelSeo\Redirectors\ConfigurationRedirector
48
     */
49 27
    public function createConfigDriver()
50
    {
51 27
        return $this->buildDriver('config');
52
    }
53
54
    /**
55
     * Build the eloquent redirector driver.
56
     *
57
     * @return \Arcanedev\LaravelSeo\Redirectors\EloquentRedirector
58
     */
59 3
    public function createEloquentDriver()
60
    {
61 3
        return $this->buildDriver('eloquent', [
62 3
            'model' => Seo::getConfig('redirects.model'),
63 1
        ]);
64
    }
65
66
    /* -----------------------------------------------------------------
67
     |  Other Methods
68
     | -----------------------------------------------------------------
69
     */
70
    /**
71
     * Build the redirector.
72
     *
73
     * @param  string  $driver
74
     * @param  array   $extra
75
     *
76
     * @return mixed
77
     */
78 30
    private function buildDriver($driver, array $extra = [])
79
    {
80 30
        $router  = $this->app->make(\Illuminate\Contracts\Routing\Registrar::class);
81 30
        $class   = Seo::getConfig("redirector.drivers.$driver.class");
82 30
        $options = Seo::getConfig("redirector.drivers.$driver.options", []);
83
84 30
        return new $class($router, array_merge($extra, $options));
85
    }
86
}
87