2013-05-18 01:42:55 +04:00
|
|
|
<?php
|
|
|
|
|
2013-05-20 17:08:20 +04:00
|
|
|
use Doctrine\Common\Cache;
|
2013-05-18 01:42:55 +04:00
|
|
|
use Doctrine\ORM\EntityManager;
|
|
|
|
|
2013-05-20 17:08:20 +04:00
|
|
|
// Path to composer autoloader. You can use different provided by your favorite framework,
|
2013-05-18 01:42:55 +04:00
|
|
|
// if you want to.
|
2013-05-20 17:08:20 +04:00
|
|
|
$loaderPath = __DIR__ . '/../../vendor/autoload.php';
|
|
|
|
if(!is_readable($loaderPath)){
|
|
|
|
throw new LogicException('Run php composer.phar install at first');
|
|
|
|
}
|
|
|
|
$loader = require $loaderPath;
|
|
|
|
|
|
|
|
// Set up class loading.
|
2013-05-18 01:42:55 +04:00
|
|
|
$loader->add('Entities', __DIR__);
|
|
|
|
$loader->add('Proxies', __DIR__);
|
|
|
|
|
2013-05-20 17:08:20 +04:00
|
|
|
$debug = true;
|
2013-05-18 01:42:55 +04:00
|
|
|
$config = new \Doctrine\ORM\Configuration();
|
|
|
|
|
|
|
|
// Set up Metadata Drivers
|
|
|
|
$driverImpl = $config->newDefaultAnnotationDriver(array(__DIR__ . "/Entities"));
|
|
|
|
$config->setMetadataDriverImpl($driverImpl);
|
|
|
|
|
2013-05-20 17:08:20 +04:00
|
|
|
// Set up caches, depending on $debug variable.
|
|
|
|
// You can use another variable to define which one of the cache systems you gonna use.
|
|
|
|
$cache = $debug ? new Cache\ArrayCache : new Cache\ApcCache;
|
2013-05-18 01:42:55 +04:00
|
|
|
$config->setMetadataCacheImpl($cache);
|
|
|
|
$config->setQueryCacheImpl($cache);
|
|
|
|
|
|
|
|
// Proxy configuration
|
|
|
|
$config->setProxyDir(__DIR__ . '/Proxies');
|
|
|
|
$config->setProxyNamespace('Proxies');
|
|
|
|
|
|
|
|
// Database connection information
|
|
|
|
$connectionOptions = array(
|
|
|
|
'driver' => 'pdo_sqlite',
|
|
|
|
'path' => 'database.sqlite'
|
|
|
|
);
|
|
|
|
|
2013-10-23 23:46:45 +04:00
|
|
|
// Enable second-level cache
|
|
|
|
$cacheConfig = new \Doctrine\ORM\Cache\CacheConfiguration();
|
|
|
|
$cacheDriver = $debug ? new Cache\ArrayCache : new Cache\ApcCache;
|
|
|
|
$cacheLogger = new \Doctrine\ORM\Cache\Logging\StatisticsCacheLogger();
|
|
|
|
$factory = new \Doctrine\ORM\Cache\DefaultCacheFactory($cacheConfig->getRegionsConfiguration(), $cacheDriver);
|
|
|
|
|
|
|
|
if ($debug) {
|
|
|
|
$cacheConfig->setCacheLogger($cacheLogger);
|
|
|
|
}
|
|
|
|
|
|
|
|
$cacheConfig->setCacheFactory($factory);
|
|
|
|
$config->setSecondLevelCacheEnabled(true);
|
|
|
|
$config->setSecondLevelCacheConfiguration($cacheConfig);
|
|
|
|
|
2013-05-18 01:42:55 +04:00
|
|
|
return EntityManager::create($connectionOptions, $config);
|