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
|
|
|
|