/**
  * Get Doctrine2Cache
  *
  * @return Doctrine\Common\Cache
  */
 public function getDoctrine2cache()
 {
     if ($this->_d2cache === null) {
         // Get Doctrine configuration options from the application.ini file
         $config = $this->getOptions();
         if (!isset($config['autoload_method'])) {
             $config['autoload_method'] = 'git';
         }
         switch ($config['autoload_method']) {
             case 'pear':
                 require_once $config['path'] . '/Tools/Setup.php';
                 Doctrine\ORM\Tools\Setup::registerAutoloadPEAR();
                 break;
             case 'dir':
                 require_once $config['path'] . '/Tools/Setup.php';
                 // FIXME
                 Doctrine\ORM\Tools\Setup::registerAutoloadDirectory();
                 break;
             case 'composer':
                 break;
             default:
                 require_once $config['path'] . '/lib/Doctrine/ORM/Tools/Setup.php';
                 Doctrine\ORM\Tools\Setup::registerAutoloadGit($config['path']);
         }
         if ($config['type'] == 'ApcCache') {
             $cache = new \Doctrine\Common\Cache\ApcCache();
         } elseif ($config['type'] == 'MemcacheCache') {
             $memcache = new Memcache();
             for ($cnt = 0; $cnt < count($config['memcache']['servers']); $cnt++) {
                 $server = $config['memcache']['servers'][$cnt];
                 $memcache->addServer(isset($server['host']) ? $server['host'] : '127.0.0.1', isset($server['port']) ? $server['port'] : 11211, isset($server['persistent']) ? $server['persistent'] : false, isset($server['weight']) ? $server['weight'] : 1, isset($server['timeout']) ? $server['timeout'] : 1, isset($server['retry_int']) ? $server['retry_int'] : 15);
             }
             $cache = new \Doctrine\Common\Cache\MemcacheCache();
             $cache->setMemcache($memcache);
         } else {
             $cache = new \Doctrine\Common\Cache\ArrayCache();
         }
         if (isset($config['namespace'])) {
             $cache->setNamespace($config['namespace']);
         }
         // stick the cache in the registry
         Zend_Registry::set('d2cache', $cache);
         $this->setDoctrine2Cache($cache);
     }
     return $this->_d2cache;
 }
示例#2
0
<?php

require_once 'Doctrine/ORM/Tools/Setup.php';
// Setup Autoloader (1)
Doctrine\ORM\Tools\Setup::registerAutoloadPEAR();
// configuration (2)
$config = new \Doctrine\ORM\Configuration();
// Proxies (3)
$config->setProxyDir(__DIR__ . '\\Doctrine\\Proxy');
$config->setProxyNamespace('Doctrine\\Proxy');
$config->setAutoGenerateProxyClasses(true);
// Driver (4)
$driverImpl = new Doctrine\ORM\Mapping\Driver\YamlDriver(array(__DIR__ . '/../application/configs/schema'));
$config->setMetadataDriverImpl($driverImpl);
// Caching Configuration (5)
$cache = new \Doctrine\Common\Cache\ArrayCache();
$config->setMetadataCacheImpl($cache);
$config->setQueryCacheImpl($cache);
$connectionOptions = array('data_fixtures_path' => __DIR__ . '/../application/configs/data/fixtures', 'models_path' => __DIR__ . '/../application/models/doctrine/models', 'migrations_path' => __DIR__ . '/../application/configs/migrations', 'sql_path' => __DIR__ . '/../application/configs/data/sql', 'yaml_schema_path' => __DIR__ . '/../application/configs/schema', 'driver' => 'pdo_mysql', 'user' => 'vlmis', 'password' => 'v123lmis', 'dbname' => 'vlmis_zr3', 'host' => '192.168.1.72');
$em = \Doctrine\ORM\EntityManager::create($connectionOptions, $config);
$platform = $em->getConnection()->getDatabasePlatform();
$platform->registerDoctrineTypeMapping('enum', 'string');
$platform->registerDoctrineTypeMapping('tinyblob', 'string');
\Doctrine\DBAL\Types\Type::addType('BlobType', 'Doctrine\\DBAL\\Types\\BlobType');
$platform->registerDoctrineTypeMapping('blob', 'BlobType');
$helperSet = new \Symfony\Component\Console\Helper\HelperSet(array('db' => new \Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper($em->getConnection()), 'em' => new \Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper($em)));