/**
  * 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;
 }
Esempio n. 2
0
<?php

use Doctrine\ORM\EntityManager, Laravel\Autoloader, Laravel\Config, Laravel\IoC;
require __DIR__ . '/lib/Doctrine/ORM/Tools/Setup.php';
Doctrine\ORM\Tools\Setup::registerAutoloadGit(__DIR__);
/**
 * Delegate the starting to an event so we can start *after* the application bundle.
 *
 * This gives the application time to override configs before we boot Doctrine.
 */
Event::listen('laravel.started: doctrine', function () {
    /**
     * Resolve the cache provider implementation from the IoC container.
     */
    if (IoC::registered('doctrine::cache.provider')) {
        $cache = IoC::resolve('doctrine::cache.provider');
    } else {
        $cache = new Doctrine\Common\Cache\ArrayCache();
    }
    /**
     * Register the cache provider with the Doctrine configuration.
     */
    $config = new Doctrine\ORM\Configuration();
    $config->setMetadataCacheImpl($cache);
    $config->setQueryCacheImpl($cache);
    /**
     * Resolve and register the meta-data driver.
     */
    if (IoC::registered('doctrine::metadata.driver')) {
        $driverImpl = IoC::resolve('doctrine::metadata.driver', array($config));
    } else {