Temporary revert

This commit is contained in:
Nicolas Le Goff
2011-12-27 16:27:04 +01:00
parent 1617d3e561
commit ccda8a86a9

View File

@@ -9,6 +9,7 @@
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
namespace Alchemy\Phrasea\Core\Service; namespace Alchemy\Phrasea\Core\Service;
use Doctrine\DBAL\Types\Type; use Doctrine\DBAL\Types\Type;
@@ -24,93 +25,16 @@ class Doctrine
protected $entityManager; protected $entityManager;
public function __construct(Array $conf) public function __construct()
{ {
require_once __DIR__ . '/../../../../vendor/doctrine2-orm/lib/vendor/doctrine-common/lib/Doctrine/Common/ClassLoader.php'; require_once __DIR__ . '/../../../../vendor/doctrine2-orm/lib/vendor/doctrine-common/lib/Doctrine/Common/ClassLoader.php';
static::loadClasses(); static::loadClasses();
$config = new \Doctrine\ORM\Configuration(); $config = new \Doctrine\ORM\Configuration();
if ($conf["debug"]["enable"]) $config->setMetadataCacheImpl(new \Doctrine\Common\Cache\ArrayCache);
{
//Force Array
$config->setMetadataCacheImpl(new \Doctrine\Common\Cache\ArrayCache());
$config->setQueryCacheImpl(new \Doctrine\Common\Cache\ArrayCache());
}
else
{
if ($conf["cache"]["query_cache"]["enable"])
{
//define query cache
switch ($conf["cache"]["query_cache"]["type"])
{
case 'memcached':
$config->setQueryCacheImpl(new \Doctrine\Common\Cache\MemcacheCache());
break;
case 'apc':
$config->setQueryCacheImpl(new \Doctrine\Common\Cache\ApcCache());
break;
case 'array':
default:
$config->setQueryCacheImpl(new \Doctrine\Common\Cache\ArrayCache());
break;
}
}
if ($conf["cache"]["metadatas_cache"]["enable"])
{
//define metadatas cache
switch ($conf["cache"]["metadatas_cache"]["type"])
{
case 'memcached':
$config->setMetadataCacheImpl(new \Doctrine\Common\Cache\MemcacheCache());
break;
case 'apc':
$config->setMetadataCacheImpl(new \Doctrine\Common\Cache\ApcCache());
break;
case 'array':
default:
$config->setMetadataCacheImpl(new \Doctrine\Common\Cache\ArrayCache());
break;
}
}
}
//define autoregeneration of proxies
if (!$conf["debug"]["enable"])
{
$config->setAutoGenerateProxyClasses(false);
}
else
{
$config->setAutoGenerateProxyClasses(true);
}
//define logger
if ($conf["debug"]["enable"] && $conf["logger"]["enable"])
{
switch ($conf["logger"]["type"])
{
case 'monolog':
$logger = new \Monolog\Logger('query-logger');
$logger->pushHandler(new \Monolog\Handler\RotatingFileHandler(
__DIR__ . '/../../../../../logs/doctrine-query.log')
, $conf["logger"]["max_day"]
);
$config->setSQLLogger(new \Doctrine\Logger\MonologSQLLogger(
$logger,
$conf["logger"]["output"])
);
break;
case 'echo':
$config->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger);
break;
default:
$config->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger);
break;
}
}
$chainDriverImpl = new \Doctrine\ORM\Mapping\Driver\DriverChain(); $chainDriverImpl = new \Doctrine\ORM\Mapping\Driver\DriverChain();
@@ -137,15 +61,15 @@ class Doctrine
'host' => $hostname, 'host' => $hostname,
'driver' => 'pdo_mysql', 'driver' => 'pdo_mysql',
); );
$evm = new \Doctrine\Common\EventManager(); $evm = new \Doctrine\Common\EventManager();
$evm->addEventSubscriber(new \Gedmo\Timestampable\TimestampableListener()); $evm->addEventSubscriber(new \Gedmo\Timestampable\TimestampableListener());
$this->entityManager = \Doctrine\ORM\EntityManager::create($conf["credentials"], $config, $evm); $this->entityManager = \Doctrine\ORM\EntityManager::create($connectionOptions, $config, $evm);
$this->addTypes(); $this->addTypes();
return $this; return $this;
} }
@@ -153,7 +77,7 @@ class Doctrine
{ {
return $this->entityManager; return $this->entityManager;
} }
public function getVersion() public function getVersion()
{ {
return \Doctrine\Common\Version::VERSION; return \Doctrine\Common\Version::VERSION;
@@ -197,33 +121,19 @@ class Doctrine
, realpath(__DIR__ . '/../../../../Doctrine') , realpath(__DIR__ . '/../../../../Doctrine')
); );
$classLoader->register(); $classLoader->register();
$classLoader = new \Doctrine\Common\ClassLoader( $classLoader = new \Doctrine\Common\ClassLoader(
'Symfony' 'Symfony'
, realpath(__DIR__ . '/../../../../vendor/doctrine2-orm/lib/vendor') , realpath(__DIR__ . '/../../../../vendor/doctrine2-orm/lib/vendor')
); );
$classLoader->register(); $classLoader->register();
$classLoader = new \Doctrine\Common\ClassLoader(
'Doctrine\Logger'
, realpath(__DIR__ . '/../../../../')
);
$classLoader->register();
$classLoader = new \Doctrine\Common\ClassLoader(
'Monolog'
, realpath(__DIR__ . '/../../../../vendor/Silex/vendor/monolog/src')
);
$classLoader->register();
$classLoader = new \Doctrine\Common\ClassLoader( $classLoader = new \Doctrine\Common\ClassLoader(
'Types' 'Types'
, realpath(__DIR__ . '/../../../../Doctrine') , realpath(__DIR__ . '/../../../../Doctrine')
); );
$classLoader->register(); $classLoader->register();
$classLoader = new \Doctrine\Common\ClassLoader( $classLoader = new \Doctrine\Common\ClassLoader(
@@ -235,22 +145,22 @@ class Doctrine
return; return;
} }
protected function addTypes() protected function addTypes()
{ {
$platform = $this->entityManager->getConnection()->getDatabasePlatform(); $platform = $this->entityManager->getConnection()->getDatabasePlatform();
Type::addType('blob', 'Types\Blob'); Type::addType('blob', 'Types\Blob');
Type::addType('enum', 'Types\Enum'); Type::addType('enum', 'Types\Enum');
Type::addType('longblob', 'Types\LongBlob'); Type::addType('longblob', 'Types\LongBlob');
Type::addType('varbinary', 'Types\VarBinary'); Type::addType('varbinary', 'Types\VarBinary');
$platform->registerDoctrineTypeMapping('enum', 'enum'); $platform->registerDoctrineTypeMapping('enum', 'enum');
$platform->registerDoctrineTypeMapping('blob', 'blob'); $platform->registerDoctrineTypeMapping('blob', 'blob');
$platform->registerDoctrineTypeMapping('longblob', 'longblob'); $platform->registerDoctrineTypeMapping('longblob', 'longblob');
$platform->registerDoctrineTypeMapping('varbinary', 'varbinary'); $platform->registerDoctrineTypeMapping('varbinary', 'varbinary');
return; return;
} }