function createDoctrineConfig($cache, $cachedAnnotationReader) { AnnotationRegistry::registerFile(dirname(__DIR__) . "/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php"); //$cache = new Doctrine\Common\Cache\ArrayCache; // if (extension_loaded('apc')) { // $cache = new \Doctrine\Common\Cache\ApcCache(); // } else { // $cache = new \Doctrine\Common\Cache\PhpFileCache(); // } $isDevMode = true; // $annotationReader = new AnnotationReader; // $cachedAnnotationReader = new Doctrine\Common\Annotations\CachedReader( // $annotationReader, // use reader // $cache // and a cache driver // ); $annotationDriver = new Doctrine\ORM\Mapping\Driver\AnnotationDriver($cachedAnnotationReader, array(__DIR__ . '/Resource')); $driverChain = new Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain(); Gedmo\DoctrineExtensions::registerAbstractMappingIntoDriverChainORM($driverChain, $cachedAnnotationReader); $driverChain->addDriver($annotationDriver, 'Uppu4\\Entity'); $config = Setup::createAnnotationMetadataConfiguration(array(__DIR__ . "/Resource"), $isDevMode); //!!!!!! $config = new Doctrine\ORM\Configuration(); $config->setProxyDir(sys_get_temp_dir()); $config->setProxyNamespace('Proxy'); $config->setAutoGenerateProxyClasses(true); // this can be based on production config. // register metadata driver $config->setMetadataDriverImpl($driverChain); // use our already initialized cache driver $config->setMetadataCacheImpl($cache); $config->setQueryCacheImpl($cache); $deleted = $cache->deleteAll(); return $config; }
public function __construct() { // load database configuration from CodeIgniter require APPPATH . 'config/database.php'; //A Doctrine Autoloader is needed to load the models // first argument of classloader is namespace and second argument is path // setup models/entity namespace $entityLoader = new ClassLoader('models', APPPATH); $entityLoader->register(); foreach (glob(APPPATH . 'modules/*', GLOB_ONLYDIR) as $m) { $module = str_replace(APPPATH . 'modules/', '', $m); $entityLoader = new ClassLoader($module, APPPATH . 'modules'); $entityLoader->register(); } //Register proxies namespace $proxyLoader = new ClassLoader('Proxies', APPPATH . 'Proxies'); $proxyLoader->register(); // Set up caches $config = new Configuration(); $cache = new ArrayCache(); $config->setMetadataCacheImpl($cache); $driverImpl = $config->newDefaultAnnotationDriver(array(APPPATH . 'models')); $config->setMetadataDriverImpl($driverImpl); $config->setQueryCacheImpl($cache); // Set up entity $reader = new AnnotationReader($cache); $models = array(APPPATH . 'models'); foreach (glob(APPPATH . 'modules/*/models', GLOB_ONLYDIR) as $m) { array_push($models, $m); } $driver = new AnnotationDriver($reader, $models); $config->setMetadataDriverImpl($driver); // Setup Gedmo $cachedAnnotationReader = new Doctrine\Common\Annotations\CachedReader($reader, $cache); // create a driver chain for metadata reading $driverChain = new Doctrine\ORM\Mapping\Driver\DriverChain(); // load superclass metadata mapping only, into driver chain // also registers Gedmo annotations.NOTE: you can personalize it Gedmo\DoctrineExtensions::registerAbstractMappingIntoDriverChainORM($driverChain, $cachedAnnotationReader); $event = new EventManager(); $timestampableListener = new TimestampableListener(); $timestampableListener->setAnnotationReader($cachedAnnotationReader); $event->addEventSubscriber($timestampableListener); $slugListener = new SluggableListener(); $slugListener->setAnnotationReader($cachedAnnotationReader); $event->addEventSubscriber($slugListener); // Proxy configuration $config->setProxyDir(APPPATH . '/proxies'); $config->setProxyNamespace('Proxies'); // Set up logger // $logger = new EchoSQLLogger; // $config->setSQLLogger($logger); $config->setAutoGenerateProxyClasses(TRUE); // Database connection information $connectionOptions = array('driver' => 'pdo_mysql', 'user' => $db['default']['username'], 'password' => $db['default']['password'], 'host' => $db['default']['hostname'], 'dbname' => $db['default']['database']); // Create EntityManager $this->em = EntityManager::create($connectionOptions, $config, $event); }
$loader->add('Gedmo', __DIR__ . '/../lib'); // autoloader for Entity namespace $loader->add('Entity', __DIR__ . '/app'); // ensure standard doctrine annotations are registered Doctrine\Common\Annotations\AnnotationRegistry::registerFile(__DIR__ . '/../vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php'); // Second configure ORM // globally used cache driver, in production use APC or memcached $cache = new Doctrine\Common\Cache\ArrayCache(); // standard annotation reader $annotationReader = new Doctrine\Common\Annotations\AnnotationReader(); $cachedAnnotationReader = new Doctrine\Common\Annotations\CachedReader($annotationReader, $cache); // create a driver chain for metadata reading $driverChain = new Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain(); // load superclass metadata mapping only, into driver chain // also registers Gedmo annotations.NOTE: you can personalize it Gedmo\DoctrineExtensions::registerAbstractMappingIntoDriverChainORM($driverChain, $cachedAnnotationReader); // now we want to register our application entities, // for that we need another metadata driver used for Entity namespace $annotationDriver = new Doctrine\ORM\Mapping\Driver\AnnotationDriver($cachedAnnotationReader, array(__DIR__ . '/app/Entity')); // NOTE: driver for application Entity can be different, Yaml, Xml or whatever // register annotation driver for our application Entity fully qualified namespace $driverChain->addDriver($annotationDriver, 'Entity'); // general ORM configuration $config = new Doctrine\ORM\Configuration(); $config->setProxyDir(sys_get_temp_dir()); $config->setProxyNamespace('Proxy'); $config->setAutoGenerateProxyClasses(false); // this can be based on production config. // register metadata driver $config->setMetadataDriverImpl($driverChain); // use our allready initialized cache driver