Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require_once APPLICATION_PATH . '/../library/Doctrine/Common/ClassLoader.php';
- use Doctrine\Common\ClassLoader,
- Doctrine\ORM\Configuration as DoctrineConfiguration,
- Doctrine\Common\EventManager as DoctrineEventManager,
- Doctrine\ORM\EntityManager as DoctrineEntityManager,
- Doctrine\Common\Cache\ApcCache as DoctrineApcCache,
- Doctrine\Common\Cache\ArrayCache as DoctrineArrayCache;
- class Bootstrap extends Zend_Application_Bootstrap_Bootstrap {
- public function _initClassLoaders() {
- debugMessage(get_include_path());
- $loader = new ClassLoader('Doctrine\ORM');
- $loader->register();
- $loader = new ClassLoader('Doctrine\Common');
- $loader->register();
- $loader = new ClassLoader('Doctrine\DBAL');
- $loader->register();
- $loader = new ClassLoader('Symfony');
- $loader->register();
- }
- public function _initDoctrineEntityManager() {
- $this->bootstrap(array('classLoaders', 'doctrineCache'));
- $zendConfig = $this->getOptions();
- // parameters required for connecting to the database.
- // the required attributes are driver, host, user, password and dbname
- $connectionParameters = $zendConfig['resources']['db']['params'];
- // Doctrine 2 expects a driver attribute instead of adapter
- $connectionParameters['driver'] = $zendConfig['resources']['db']['adapter'];
- // Doctrine 2 expects a user variable instead of username so change it here
- $connectionParameters['user'] = $connectionParameters['username'];
- // now initialize the configuration object
- $configuration = new DoctrineConfiguration();
- // the metadata cache is used to avoid parsing all mapping information every time
- // the framework is initialized.
- $configuration->setMetadataCacheImpl($this->getResource('doctrineCache'));
- // for performance reasons, it is also recommended to use a result cache
- $configuration->setResultCacheImpl($this->getResource('doctrineCache'));
- // if you set this option to true, Doctrine 2 will generate proxy classes for your entities
- // on the fly. This has of course impact on the performance and should therefore be disabled
- // in the production environment
- $configuration->setAutoGenerateProxyClasses($zendConfig['doctrine']['autoGenerateProxyClasses']);
- // the directory, where your proxy classes live
- $configuration->setProxyDir($zendConfig['doctrine']['proxyPath']);
- // the proxy classes' namespace
- $configuration->setProxyNamespace($zendConfig['doctrine']['proxyNamespace']);
- // the next option tells doctrine which description language we want to use for the mapping
- // information
- $configuration->setMetadataDriverImpl(
- $configuration->newDefaultAnnotationDriver(
- $zendConfig['doctrine']['entityPath']));
- // next, we create an event manager
- $eventManager = new DoctrineEventManager();
- // now we have everything required to initialize the entity manager
- $entityManager = DoctrineEntityManager::create($connectionParameters, $configuration, $eventManager);
- Zend_Registry::set('em', $entityManager);
- $cmf = $entityManager->getMetadataFactory();
- $class = $cmf->getMetadataFor('AclGroup');
- debugMessage($class);
- return $entityManager;
- }
- /**
- * @return Doctrine\Common\CacheProvider
- */
- public function _initDoctrineCache() {
- $cache = null;
- if (APPLICATION_ENV === 'development') {
- $cache = new DoctrineArrayCache();
- } else {
- $cache = new DoctrineArrayCache(); // could be changed depending on what the hosting provider supports
- }
- return $cache;
- }
- /**
- * Intialize the memory usage logging
- *
- public function _initEnableMemoryUsageLogging() {
- $writer = new Zend_Log_Writer_Stream ( APPLICATION_PATH. '/logs/memory_usage.log' );
- $log = new Zend_Log ( $writer );
- $plugin = new MemoryPeakUsageLog ( $log );
- // Use a high stack index to delay execution until other
- // plugins are finished, and their memory can also be accounted for.
- Zend_Controller_Front::getInstance()->registerPlugin ($plugin, 1000 );
- }*/
- /**
- * Initialize the email template
- */
- public function _initMail() {
- # Zend Mail instance
- // create a new instance
- $mailer = new Zend_Mail('utf8');
- // set the default transport configured in application.ini
- $mailer->setDefaultTransport($this->getPluginResource('mail')->getMail());
- // set the default to and from addresses
- $mail_config = new Zend_Config($this->getPluginResource('mail')->getOptions());
- $mailer->setDefaultFrom($mail_config->defaultFrom->email, $mail_config->defaultFrom->name);
- $mailer->setDefaultReplyTo($mail_config->defaultReplyTo->email, $mail_config->defaultReplyTo->name);
- // add the mail instance to the registry
- Zend_Registry::set("mail", $mailer);
- }
- /**
- * Initialize the logger, cache and translate instances
- *
- */
- public function _initEnv() {
- Zend_Registry::set("log", $this->getPluginResource('log')->getLog());
- Zend_Registry::set("translate", $this->getPluginResource('translate')->getTranslate());
- Zend_Registry::set("cache", $this->getPluginResource('cachemanager')->getCacheManager()->getCache('cache'));
- // the database adapter for the session
- Zend_Registry::set("dbAdapter", $this->getPluginResource('db')->getDbAdapter());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement