| Total Complexity | 4 |
| Total Lines | 37 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 23 | class ConfigProvider implements ServiceProviderInterface |
||
| 24 | { |
||
| 25 | public const SERVICE_NAME = 'config'; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * Register config provider |
||
| 29 | * |
||
| 30 | * @param \Phalcon\Di\DiInterface $di |
||
| 31 | * |
||
| 32 | * @throws \Phalcon\Exception |
||
| 33 | */ |
||
| 34 | public function register(DiInterface $di): void |
||
| 35 | { |
||
| 36 | $configPath = '/etc/inc/mikopbx-settings.json'; |
||
| 37 | |||
| 38 | if ( ! file_exists($configPath) |
||
| 39 | || ! is_readable($configPath) |
||
| 40 | ) { |
||
| 41 | throw new Exception('Config file does not exist: ' . $configPath); |
||
| 42 | } |
||
| 43 | |||
| 44 | $di->setShared( |
||
| 45 | self::SERVICE_NAME, |
||
| 46 | function () use ($configPath) { |
||
| 47 | return new Json($configPath); |
||
| 48 | } |
||
| 49 | ); |
||
| 50 | } |
||
| 51 | |||
| 52 | /** |
||
| 53 | * Recreates modules service after enable or disable them |
||
| 54 | */ |
||
| 55 | public static function recreateConfigProvider(): void |
||
| 60 | } |
||
| 61 | } |