1
|
|
|
<?php namespace Arcanedev\EmbedVideo; |
2
|
|
|
|
3
|
|
|
use Illuminate\Support\Manager; |
4
|
|
|
use Arcanedev\EmbedVideo\Contracts\ParserManager as ParserManagerContract; |
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* Class ParserManager |
8
|
|
|
* |
9
|
|
|
* @package Arcanedev\EmbedVideo |
10
|
|
|
* @author ARCANEDEV <[email protected]> |
11
|
|
|
*/ |
12
|
|
|
class ParserManager extends Manager implements ParserManagerContract |
13
|
|
|
{ |
14
|
|
|
/* ----------------------------------------------------------------- |
15
|
|
|
| Getters & Setters |
16
|
|
|
| ----------------------------------------------------------------- |
17
|
|
|
*/ |
18
|
|
|
/** |
19
|
|
|
* Get the default driver name. |
20
|
|
|
* |
21
|
|
|
* @return string |
22
|
|
|
*/ |
23
|
|
|
public function getDefaultDriver() |
24
|
|
|
{ |
25
|
|
|
return $this->getConfig('default'); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/* ----------------------------------------------------------------- |
29
|
|
|
| Constructor |
30
|
|
|
| ----------------------------------------------------------------- |
31
|
|
|
*/ |
32
|
|
|
/** |
33
|
|
|
* Create a new manager instance. |
34
|
|
|
* |
35
|
|
|
* @param \Illuminate\Foundation\Application $app |
36
|
|
|
*/ |
37
|
81 |
|
public function __construct($app) |
38
|
|
|
{ |
39
|
81 |
|
parent::__construct($app); |
40
|
|
|
|
41
|
81 |
|
$this->registerParser(); |
42
|
81 |
|
} |
43
|
|
|
|
44
|
|
|
/* ----------------------------------------------------------------- |
45
|
|
|
| Main Methods |
46
|
|
|
| ----------------------------------------------------------------- |
47
|
|
|
*/ |
48
|
|
|
/** |
49
|
|
|
* Get a video parser implementation. |
50
|
|
|
* |
51
|
|
|
* @param string $parser |
52
|
|
|
* |
53
|
|
|
* @return \Arcanedev\EmbedVideo\Contracts\Parser |
54
|
|
|
*/ |
55
|
78 |
|
public function parser($parser = null) |
56
|
|
|
{ |
57
|
78 |
|
return $this->driver($parser); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/* ----------------------------------------------------------------- |
61
|
|
|
| Other Methods |
62
|
|
|
| ----------------------------------------------------------------- |
63
|
|
|
*/ |
64
|
|
|
/** |
65
|
|
|
* Get the config repository. |
66
|
|
|
* |
67
|
|
|
* @return \Illuminate\Contracts\Config\Repository |
68
|
|
|
*/ |
69
|
81 |
|
protected function config() |
70
|
|
|
{ |
71
|
81 |
|
return $this->app['config']; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Get a config value. |
76
|
|
|
* |
77
|
|
|
* @param string $key |
78
|
|
|
* @param mixed|null $default |
79
|
|
|
* |
80
|
|
|
* @return mixed |
81
|
|
|
*/ |
82
|
81 |
|
protected function getConfig($key, $default = null) |
83
|
|
|
{ |
84
|
81 |
|
return $this->config()->get("embed-video.{$key}", $default); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Register the parsers. |
89
|
|
|
*/ |
90
|
81 |
|
private function registerParser() |
91
|
|
|
{ |
92
|
81 |
|
foreach ($this->getConfig('parsers') as $driver => $configs) { |
93
|
81 |
|
$this->extend($driver, function () use ($driver, $configs) { |
94
|
78 |
|
return $this->buildParser($driver, $configs); |
95
|
81 |
|
}); |
96
|
27 |
|
} |
97
|
81 |
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* Build the parser. |
101
|
|
|
* |
102
|
|
|
* @param string $driver |
103
|
|
|
* @param array $configs |
104
|
|
|
* |
105
|
|
|
* @return \Arcanedev\EmbedVideo\Contracts\Parser |
106
|
|
|
*/ |
107
|
78 |
|
private function buildParser($driver, array $configs) |
|
|
|
|
108
|
|
|
{ |
109
|
78 |
|
return new $configs['class']( |
110
|
78 |
|
$configs['options'] |
111
|
26 |
|
); |
112
|
|
|
} |
113
|
|
|
} |
114
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.