|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file is part of the m1\vars library |
|
5
|
|
|
* |
|
6
|
|
|
* (c) m1 <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
* |
|
11
|
|
|
* @package m1/vars |
|
12
|
|
|
* @version 0.2.0 |
|
13
|
|
|
* @author Miles Croxford <[email protected]> |
|
14
|
|
|
* @copyright Copyright (c) Miles Croxford <[email protected]> |
|
15
|
|
|
* @license http://github.com/m1/vars/blob/master/LICENSE |
|
16
|
|
|
* @link http://github.com/m1/vars/blob/master/README.MD Documentation |
|
17
|
|
|
*/ |
|
18
|
|
|
|
|
19
|
|
|
namespace M1\Vars\Provider\Silex; |
|
20
|
|
|
|
|
21
|
|
|
use Silex\Application; |
|
22
|
|
|
use Silex\ServiceProviderInterface; |
|
23
|
|
|
use M1\Vars\Vars; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* The Silex service provider for Vars |
|
27
|
|
|
* |
|
28
|
|
|
* @since 0.1.0 |
|
29
|
|
|
*/ |
|
30
|
|
|
class VarsServiceProvider implements ServiceProviderInterface |
|
31
|
|
|
{ |
|
32
|
|
|
/** |
|
33
|
|
|
* The entity to use Vars with |
|
34
|
|
|
* |
|
35
|
|
|
* @var null |
|
36
|
|
|
*/ |
|
37
|
|
|
private $entity; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* The available option keys |
|
41
|
|
|
* |
|
42
|
|
|
* @var array |
|
43
|
|
|
*/ |
|
44
|
|
|
private $option_keys = array( |
|
45
|
|
|
'cache', |
|
46
|
|
|
'cache_path', |
|
47
|
|
|
'cache_expire', |
|
48
|
|
|
'loaders', |
|
49
|
|
|
'variables' |
|
50
|
|
|
); |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* The service provider constructor sets the entity to use with vars |
|
54
|
|
|
* |
|
55
|
|
|
* @param mixed $entity The entity |
|
56
|
|
|
*/ |
|
57
|
3 |
|
public function __construct($entity = null) |
|
58
|
|
|
{ |
|
59
|
3 |
|
$this->entity = $entity; |
|
60
|
3 |
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Registers the service provider, sets the user defined options and returns the vars instance |
|
64
|
|
|
* |
|
65
|
|
|
* @param \Silex\Application $app The silex app |
|
66
|
|
|
*/ |
|
67
|
|
|
public function register(Application $app) |
|
68
|
|
|
{ |
|
69
|
3 |
|
$app['vars'] = function ($app) { |
|
70
|
3 |
|
$options = array(); |
|
71
|
|
|
|
|
72
|
3 |
|
if (isset($app['vars.path'])) { |
|
73
|
1 |
|
$options['base_path'] = $app['vars.path']; |
|
74
|
1 |
|
} |
|
75
|
|
|
|
|
76
|
3 |
|
if (isset($app['vars.options'])) { |
|
77
|
2 |
|
$keyed_options = $app['vars.options']; |
|
78
|
|
|
|
|
79
|
2 |
|
foreach ($this->option_keys as $option) { |
|
80
|
2 |
|
if (isset($keyed_options[$option])) { |
|
81
|
2 |
|
$options[$option] = $keyed_options[$option]; |
|
82
|
2 |
|
} |
|
83
|
2 |
|
} |
|
84
|
2 |
|
} |
|
85
|
|
|
|
|
86
|
3 |
|
if (isset($app['debug']) && $app['debug']) { |
|
87
|
1 |
|
$options['cache'] = false; |
|
88
|
1 |
|
} |
|
89
|
|
|
|
|
90
|
3 |
|
return new Vars($this->entity, $options); |
|
91
|
|
|
}; |
|
92
|
3 |
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* The silex service provider boot function |
|
96
|
|
|
* |
|
97
|
|
|
* @param \Silex\Application $app The silex app |
|
98
|
|
|
* |
|
99
|
|
|
* @codeCoverageIgnore |
|
100
|
|
|
*/ |
|
101
|
|
|
public function boot(Application $app) |
|
102
|
|
|
{ |
|
103
|
|
|
} |
|
104
|
|
|
} |
|
105
|
|
|
|