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->getConfig('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
|
|
|
* Get a driver instance. |
44
|
|
|
* |
45
|
|
|
* @param string $driver |
46
|
|
|
* |
47
|
|
|
* @return \Arcanedev\LaravelSeo\Contracts\Redirector |
48
|
|
|
*/ |
49
|
30 |
|
public function driver($driver = null) |
50
|
|
|
{ |
51
|
30 |
|
return parent::driver($driver); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Build the config redirector driver. |
56
|
|
|
* |
57
|
|
|
* @return \Arcanedev\LaravelSeo\Redirectors\ConfigurationRedirector |
58
|
|
|
*/ |
59
|
27 |
|
public function createConfigDriver() |
60
|
|
|
{ |
61
|
27 |
|
return $this->buildDriver('config'); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Build the eloquent redirector driver. |
66
|
|
|
* |
67
|
|
|
* @return \Arcanedev\LaravelSeo\Redirectors\EloquentRedirector |
68
|
|
|
*/ |
69
|
3 |
|
public function createEloquentDriver() |
70
|
|
|
{ |
71
|
3 |
|
return $this->buildDriver('eloquent', [ |
72
|
3 |
|
'model' => $this->getConfig('redirects.model'), |
73
|
1 |
|
]); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/* ----------------------------------------------------------------- |
77
|
|
|
| Other Methods |
78
|
|
|
| ----------------------------------------------------------------- |
79
|
|
|
*/ |
80
|
|
|
/** |
81
|
|
|
* Build the redirector. |
82
|
|
|
* |
83
|
|
|
* @param string $driver |
84
|
|
|
* @param array $extra |
85
|
|
|
* |
86
|
|
|
* @return mixed |
87
|
|
|
*/ |
88
|
30 |
|
private function buildDriver($driver, array $extra = []) |
89
|
|
|
{ |
90
|
30 |
|
$router = $this->app->make(\Illuminate\Contracts\Routing\Registrar::class); |
91
|
30 |
|
$class = $this->getConfig("redirector.drivers.$driver.class"); |
92
|
30 |
|
$options = $this->getConfig("redirector.drivers.$driver.options", []); |
93
|
|
|
|
94
|
30 |
|
return new $class($router, array_merge($extra, $options)); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* Get the seo config. |
99
|
|
|
* |
100
|
|
|
* @param string $key |
101
|
|
|
* @param mixed|null $default |
102
|
|
|
* |
103
|
|
|
* @return mixed |
104
|
|
|
*/ |
105
|
33 |
|
private function getConfig($key, $default = null) |
106
|
|
|
{ |
107
|
33 |
|
return $this->config()->get("seo.$key", $default); |
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
|