-
Notifications
You must be signed in to change notification settings - Fork 613
Expand file tree
/
Copy pathConfigProvider.php
More file actions
48 lines (42 loc) · 1.24 KB
/
Copy pathConfigProvider.php
File metadata and controls
48 lines (42 loc) · 1.24 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
<?php
declare(strict_types=1);
/**
* This file is part of the Phalcon Developer Tools.
*
* (c) Phalcon Team <team@phalcon.io>
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Phalcon\DevTools\Providers;
use Phalcon\Config\Config;
use Phalcon\DevTools\Scanners\Config as ConfigScanner;
use Phalcon\Di\DiInterface;
use Phalcon\Di\ServiceProviderInterface;
class ConfigProvider implements ServiceProviderInterface
{
/**
* @var string
*/
protected $providerName = 'config';
/**
* Registers a service provider.
*
* @param DiInterface $di
*/
public function register(DiInterface $di): void
{
$basePath = $di->getShared('application')->getBasePath();
$di->setShared($this->providerName, function () use ($basePath) {
$scanner = new ConfigScanner($basePath);
$config = $scanner->load('config');
if (ENV_PRODUCTION !== APPLICATION_ENV) {
$override = $scanner->scan(APPLICATION_ENV);
if ($override instanceof Config) {
$config->merge($override);
}
}
return $config;
});
}
}