Loaders for Container
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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\<className> or \Custom\Espo\Core\Loaders\<className> 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(
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace Espo\Core\Loaders;
|
||||
|
||||
use Doctrine\ORM\Tools\Setup,
|
||||
Espo\Core\Doctrine\ORM\Mapping\Driver\EspoPHPDriver;
|
||||
|
||||
class EntityManager
|
||||
{
|
||||
private $container;
|
||||
|
||||
|
||||
function __construct(\Espo\Core\Container $container)
|
||||
{
|
||||
$this->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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
@@ -1,48 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Espo\Core\Utils;
|
||||
|
||||
use Doctrine\ORM\Tools\Setup,
|
||||
Espo\Core\Doctrine\ORM\Mapping\Driver\EspoPHPDriver;
|
||||
|
||||
class EntityManager
|
||||
{
|
||||
private $config;
|
||||
|
||||
|
||||
function __construct(\Espo\Core\Utils\Config $config)
|
||||
{
|
||||
$this->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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user