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 require_once dirname(__FILE__
) . '/../../interface/globals.php';
13 use Symfony\Component\DependencyInjection\Reference
;
14 use Symfony\Component\DependencyInjection\Definition
;
15 use Symfony\Component\DependencyInjection\ContainerBuilder
;
16 use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag
;
17 use Symfony\Component\EventDispatcher\EventDispatcher
;
18 use Symfony\Component\EventDispatcher\DependencyInjection\RegisterListenersPass
;
23 * This is the core of OpenEMR. It is a thin class enabling service containers,
24 * event dispatching for now.
28 * @author Robert Down <robertdown@live.com>
29 * @copyright Copyright (c) 2017 Robert Down
33 /** @var ContainerBuilder */
36 public function __construct()
38 $this->prepareContainer();
42 * Setup the initial container
44 private function prepareContainer()
46 if (!$this->container
) {
47 $builder = new ContainerBuilder(new ParameterBag());
48 $builder->addCompilerPass(new RegisterListenersPass());
49 $definition = new Definition(EventDispatcher
::class, [new Reference('service_container')]);
50 $definition->setPublic(true);
51 $builder->setDefinition('event_dispatcher', $definition);
53 $this->container
= $builder;
58 * Return true if the environment variable OPENEMR__ENVIRONMENT is set to dev.
62 public function isDev()
64 return (($_ENV['OPENEMR__ENVIRONMENT'] ??
'') === 'dev') ?
true : false;
68 * Get the Service Container
70 * @return ContainerBuilder
72 public function getContainer()
74 if (!$this->container
) {
75 $this->prepareContainer();
78 return $this->container
;
82 * Get the Event Dispatcher
84 * @return EventDispatcher
87 public function getEventDispatcher()
89 if ($this->container
) {
90 /** @var EventDispatcher $dispatcher */
91 return $this->container
->get('event_dispatcher');
93 throw new \
Exception('Container does not exist');