add yet another mariadb short term release to ci (#6004)
[openemr.git] / src / Core / Kernel.php
blobd2d1495eada75c2d238c064f80110a06e0c658e3
1 <?php
3 /**
4 * OpenEMR <https://open-emr.org>.
6 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
7 */
9 namespace OpenEMR\Core;
11 use Symfony\Component\DependencyInjection\Reference;
12 use Symfony\Component\DependencyInjection\Definition;
13 use Symfony\Component\DependencyInjection\ContainerBuilder;
14 use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
15 use Symfony\Component\EventDispatcher\EventDispatcher;
16 use Symfony\Component\EventDispatcher\DependencyInjection\RegisterListenersPass;
18 /**
19 * Class Kernel.
21 * This is the core of OpenEMR. It is a thin class enabling service containers,
22 * event dispatching for now.
24 * @package OpenEMR
25 * @subpackage Core
26 * @author Robert Down <robertdown@live.com>
27 * @copyright Copyright (c) 2017-2022 Robert Down
29 class Kernel
31 /** @var ContainerBuilder */
32 private $container;
34 public function __construct()
36 $this->prepareContainer();
39 /**
40 * Setup the initial container
42 private function prepareContainer()
44 if (!$this->container) {
45 $builder = new ContainerBuilder(new ParameterBag());
46 $builder->addCompilerPass(new RegisterListenersPass());
47 $definition = new Definition(EventDispatcher::class, [new Reference('service_container')]);
48 $definition->setPublic(true);
49 $builder->setDefinition('event_dispatcher', $definition);
50 $builder->compile();
51 $this->container = $builder;
55 /**
56 * Return true if the environment variable OPENEMR__ENVIRONMENT is set to dev.
58 * @return bool
60 public function isDev()
62 return (($_ENV['OPENEMR__ENVIRONMENT'] ?? '') === 'dev') ? true : false;
65 /**
66 * Get the Service Container
68 * @return ContainerBuilder
70 public function getContainer()
72 if (!$this->container) {
73 $this->prepareContainer();
76 return $this->container;
79 /**
80 * Get the Event Dispatcher
82 * @return EventDispatcher
83 * @throws \Exception
85 public function getEventDispatcher()
87 if ($this->container) {
88 /** @var EventDispatcher $dispatcher */
89 return $this->container->get('event_dispatcher');
90 } else {
91 throw new \Exception('Container does not exist');