4 * OpenEMR <https://open-emr.org>.
6 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
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
;
21 * This is the core of OpenEMR. It is a thin class enabling service containers,
22 * event dispatching for now.
26 * @author Robert Down <robertdown@live.com>
27 * @copyright Copyright (c) 2017-2022 Robert Down
31 /** @var ContainerBuilder */
34 public function __construct()
36 $this->prepareContainer();
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);
51 $this->container
= $builder;
56 * Return true if the environment variable OPENEMR__ENVIRONMENT is set to dev.
60 public function isDev()
62 return (($_ENV['OPENEMR__ENVIRONMENT'] ??
'') === 'dev') ?
true : false;
66 * Get the Service Container
68 * @return ContainerBuilder
70 public function getContainer()
72 if (!$this->container
) {
73 $this->prepareContainer();
76 return $this->container
;
80 * Get the Event Dispatcher
82 * @return EventDispatcher
85 public function getEventDispatcher()
87 if ($this->container
) {
88 /** @var EventDispatcher $dispatcher */
89 return $this->container
->get('event_dispatcher');
91 throw new \
Exception('Container does not exist');