Repository navigation
Expand file tree
/
Copy pathServiceProvider.php
More file actions
70 lines (60 loc) · 1.67 KB
/
Copy pathServiceProvider.php
File metadata and controls
70 lines (60 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
namespace Dingo\Api\Provider;
use Illuminate\Support\ServiceProvider as IlluminateServiceProvider;
abstract class ServiceProvider extends IlluminateServiceProvider
{
/**
* Array of config items that are instantiable.
*
* @var array
*/
protected $instantiable = [
'middleware', 'auth', 'throttling', 'transformer', 'formats',
];
/**
* Retrieve and instantiate a config value if it exists and is a class.
*
* @param string $item
* @param bool $instantiate
*
* @return mixed
*/
protected function config($item, $instantiate = true)
{
$value = $this->app['config']->get('api.'.$item);
if (is_array($value)) {
return $instantiate ? $this->instantiateConfigValues($item, $value) : $value;
}
return $instantiate ? $this->instantiateConfigValue($item, $value) : $value;
}
/**
* Instantiate an array of instantiable configuration values.
*
* @param string $item
* @param array $values
*
* @return array
*/
protected function instantiateConfigValues($item, array $values)
{
foreach ($values as $key => $value) {
$values[$key] = $this->instantiateConfigValue($item, $value);
}
return $values;
}
/**
* Instantiate an instantiable configuration value.
*
* @param string $item
* @param mixed $value
*
* @return mixed
*/
protected function instantiateConfigValue($item, $value)
{
if (is_string($value) && in_array($item, $this->instantiable)) {
return $this->app->make($value);
}
return $value;
}
}