1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of the Zemit Framework. |
4
|
|
|
* |
5
|
|
|
* (c) Zemit Team <[email protected]> |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE.txt |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace Zemit\Provider\Config; |
12
|
|
|
|
13
|
|
|
use Phalcon\Di\DiInterface; |
14
|
|
|
use Zemit\Bootstrap; |
15
|
|
|
use Zemit\Bootstrap\Config; |
16
|
|
|
use Zemit\Provider\AbstractServiceProvider; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Class ServiceProvider |
20
|
|
|
* |
21
|
|
|
* @author Julien Turbide <[email protected]> |
22
|
|
|
* @copyright Zemit Team <[email protected]> |
23
|
|
|
* |
24
|
|
|
* @since 1.0 |
25
|
|
|
* @version 1.0 |
26
|
|
|
* |
27
|
|
|
* @package Zemit\Provider\Config |
28
|
|
|
*/ |
29
|
|
|
class ServiceProvider extends AbstractServiceProvider |
30
|
|
|
{ |
31
|
|
|
protected $serviceName = 'config'; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* {@inheritdoc} |
35
|
|
|
* |
36
|
|
|
* @param DiInterface $di |
37
|
|
|
*/ |
38
|
|
|
public function register(DiInterface $di = null): void |
39
|
|
|
{ |
40
|
|
|
// Set shared service in DI |
41
|
|
|
$di->setShared($this->getName(), function() use ($di) { |
|
|
|
|
42
|
|
|
|
43
|
|
|
/** @var Bootstrap $bootstrap */ |
44
|
|
|
$bootstrap = $di->get('bootstrap'); |
|
|
|
|
45
|
|
|
|
46
|
|
|
$config = $bootstrap->config ?? new Config(); |
47
|
|
|
if (is_string($config) && class_exists($config)) { |
|
|
|
|
48
|
|
|
$config = new $config(); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
// Inject some dynamic variables |
52
|
|
|
$config->mode = $di->get('bootstrap')->getMode(); |
|
|
|
|
53
|
|
|
|
54
|
|
|
// Merge config with current environment |
55
|
|
|
$config->mergeEnvConfig(); |
56
|
|
|
|
57
|
|
|
// Launch bootstrap prepare raw php configs |
58
|
|
|
$bootstrap->prepare->php($config->path('app')); |
59
|
|
|
|
60
|
|
|
// Register other providers |
61
|
|
|
// foreach ($config->providers as $provider) { |
62
|
|
|
// $di->register(new $provider($di)); |
63
|
|
|
// } |
64
|
|
|
|
65
|
|
|
// Set the config |
66
|
|
|
return $config; |
67
|
|
|
}); |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|