diff --git a/application/Espo/Core/Application.php b/application/Espo/Core/Application.php index 2cddce3224..4c2af5349c 100644 --- a/application/Espo/Core/Application.php +++ b/application/Espo/Core/Application.php @@ -185,13 +185,13 @@ EOT; ); }); - $this->getSlim()->put('/metadata/:type/:scope/', function() { + /*$this->getSlim()->put('/metadata/:type/:scope/', function() { return array( 'controller' => 'Metadata', 'scope' => ':scope', 'action' => ':type', ); - })->conditions( array('upper' => array('scope')) ); + })->conditions( array('upper' => array('scope')) ); */ //END: METADATA //SETTINGS diff --git a/application/Espo/Core/Container.php b/application/Espo/Core/Container.php index b20e91d415..b86f774f25 100644 --- a/application/Espo/Core/Container.php +++ b/application/Espo/Core/Container.php @@ -15,7 +15,7 @@ class Container { } - + public function get($name) { @@ -32,8 +32,20 @@ class Container if (method_exists($this, $loadMethod)) { $this->$loadMethod(); } else { - // TODO external loader class (\Espo\Core\Loaders\EntityManager::load()) + //external loader class \Espo\Core\Loaders\ or \Custom\Espo\Core\Loaders\ with load() method + $className = '\Custom\Espo\Core\Loaders\\'.ucfirst($name); + if (!class_exists($className)) { + $className = '\Espo\Core\Loaders\\'.ucfirst($name); + } + + if (class_exists($className)) { + $loadClass = new $className($this); + $this->data[$name] = $loadClass->load(); + } } + + // TODO throw an exception + return null; } @@ -116,14 +128,6 @@ class Container ); } - private function loadEntityManager() - { - $espoEM = new \Espo\Core\Utils\EntityManager( - $this->get('config') - ); - $this->data['entityManager'] = $espoEM->create(); - } - private function loadControllerManager() { $this->data['controllerManager'] = new \Espo\Core\Controllers\Manager( diff --git a/application/Espo/Core/Loaders/EntityManager.php b/application/Espo/Core/Loaders/EntityManager.php new file mode 100644 index 0000000000..05db3bb438 --- /dev/null +++ b/application/Espo/Core/Loaders/EntityManager.php @@ -0,0 +1,48 @@ +container = $container; + } + + protected function getContainer() + { + return $this->container; + } + + + public function load() + { + //EspoPHPDriver for Doctrine + $devMode= !$this->getContainer()->get('config')->get('useCache'); + $doctrineConfig = Setup::createConfiguration($devMode, null, null); + $doctrineConfig->setMetadataDriverImpl(new EspoPHPDriver( + array( + $this->getContainer()->get('config')->get('metadataConfig')->doctrineCache, + $this->getContainer()->get('config')->get('defaultsPath').'/doctrine/metadata' + ) + )); + //END: EspoPHPDriver for Doctrine + + $doctrineConn = (array) $this->getContainer()->get('config')->get('database'); + + // obtaining the entity manager + return \Doctrine\ORM\EntityManager::create($doctrineConn, $doctrineConfig); + } + + + +} + + +?> \ No newline at end of file diff --git a/application/Espo/Core/Utils/EntityManager.php b/application/Espo/Core/Utils/EntityManager.php deleted file mode 100644 index 8738f2eea1..0000000000 --- a/application/Espo/Core/Utils/EntityManager.php +++ /dev/null @@ -1,48 +0,0 @@ -config = $config; - } - - public function getConfig() - { - return $this->config; - } - - - public function create() - { - //EspoPHPDriver for Doctrine - $devMode= !$this->getConfig()->get('useCache'); - $doctrineConfig = Setup::createConfiguration($devMode, null, null); - $doctrineConfig->setMetadataDriverImpl(new EspoPHPDriver( - array( - $this->getConfig()->get('metadataConfig')->doctrineCache, - $this->getConfig()->get('defaultsPath').'/doctrine/metadata' - ) - )); - //END: EspoPHPDriver for Doctrine - - $doctrineConn = (array) $this->getConfig()->get('database'); - - // obtaining the entity manager - return \Doctrine\ORM\EntityManager::create($doctrineConn, $doctrineConfig); - } - - - -} - - -?> \ No newline at end of file