/**
  * Add driverChain and get orm config
  *
  * @return \Doctrine\ORM\Configuration
  */
 public function getConfiguration()
 {
     $driverChain = $this->getMetadataDriverImpl();
     // Inject the driverChain into the doctrine config
     $this->configuration->setMetadataDriverImpl($driverChain);
     return $this->configuration;
 }
Beispiel #2
0
 private function obterConfiguracao($dados)
 {
     $this->config = new Configuration();
     // Definição do driver de mapeamento
     $metadata_driver = "Doctrine\\ORM\\Mapping\\Driver\\{$dados['metadata_driver']}";
     if ($dados['metadata_driver'] == "AnnotationDriver") {
         $driver = $this->config->newDefaultAnnotationDriver(array(MODELO), true);
     } else {
         $driver = new $metadata_driver(CONFIG . DS . 'orm');
     }
     if (!empty($dados['map_paths'])) {
         $driver->addPaths(preg_split('/, ?/', $dados['map_paths']));
     }
     $this->config->setMetadataDriverImpl($driver);
     // Configurações de proxies
     $this->config->setProxyDir(RAIZ . DS . $dados['proxy_dir']);
     $this->config->setProxyNamespace($dados['proxy_namespace']);
     $this->config->setAutoGenerateProxyClasses($dados['auto_proxies']);
     // Definição da estratégia de caches de consultas e metadados
     $metadata_cache = "Doctrine\\Common\\Cache\\{$dados['metadata_cache']}";
     $query_cache = "Doctrine\\Common\\Cache\\{$dados['query_cache']}";
     $result_cache = "Doctrine\\Common\\Cache\\{$dados['query_cache']}";
     $this->config->setMetadataCacheImpl(new $metadata_cache());
     $this->config->setQueryCacheImpl(new $query_cache());
     $this->config->setResultCacheImpl(new $result_cache());
     // Ferramenta de log de consultas
     if (!empty($dados['sql_logger'])) {
         $sql_logger = "Doctrine\\DBAL\\Logging\\{$dados['sql_logger']}";
         $logger = new $sql_logger();
         $this->config->setSQLLogger($logger);
     }
 }
Beispiel #3
0
 /**
  * Get the Doctrine Configuration object
  *
  * @return \Doctrine\ORM\Configuration
  */
 public function getConfig()
 {
     if (null === $this->_config) {
         $this->_config = new \Doctrine\ORM\Configuration();
         $this->_config->setMetadataDriverImpl($this->getDriver());
     }
     return $this->_config;
 }
Beispiel #4
0
 public function testSetGetMetadataDriverImpl()
 {
     $this->assertSame(null, $this->configuration->getMetadataDriverImpl());
     // defaults
     $metadataDriver = $this->getMock('Doctrine\\Common\\Persistence\\Mapping\\Driver\\MappingDriver');
     $this->configuration->setMetadataDriverImpl($metadataDriver);
     $this->assertSame($metadataDriver, $this->configuration->getMetadataDriverImpl());
 }
Beispiel #5
0
 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);
 }
 public function setUp()
 {
     $this->configuration = new Configuration();
     $this->configuration->setMetadataCacheImpl(new ArrayCache());
     $this->configuration->setQueryCacheImpl(new ArrayCache());
     $this->configuration->setProxyDir(__DIR__ . '/Proxies');
     $this->configuration->setProxyNamespace('DoctrineExtensions\\Tests\\Proxies');
     $this->configuration->setAutoGenerateProxyClasses(true);
     $this->configuration->setMetadataDriverImpl($this->configuration->newDefaultAnnotationDriver(__DIR__ . '/../Entities'));
     $this->entityManager = EntityManager::create(array('driver' => 'pdo_sqlite', 'memory' => true), $this->configuration);
 }
 public function __construct()
 {
     //cargamos la configuración de base de datos de codeigniter
     require APPPATH . "config/database.php";
     //utilizamos el namespace Entities para mapear el directorio models
     $entitiesClassLoader = new ClassLoader('Entities', rtrim(APPPATH . "models"));
     $entitiesClassLoader->register();
     //utilizamos el namespace Proxies para mapear el directorio models/proxies
     $proxiesClassLoader = new ClassLoader('Proxies', APPPATH . 'models/proxies');
     $proxiesClassLoader->register();
     // Configuración y chaché
     $config = new Configuration();
     $cache = new ArrayCache();
     $config->setMetadataCacheImpl($cache);
     $driverImpl = $config->newDefaultAnnotationDriver(array(APPPATH . 'models/entities'));
     $config->setMetadataDriverImpl($driverImpl);
     $config->setQueryCacheImpl($cache);
     $config->setQueryCacheImpl($cache);
     // Configuración Proxy
     $config->setProxyDir(APPPATH . '/models/proxies');
     $config->setProxyNamespace('Proxies');
     // Habilitar el logger para obtener información de cada proceso
     $logger = new EchoSQLLogger();
     //$config->setSQLLogger($logger);
     $config->setAutoGenerateProxyClasses(TRUE);
     //configuramos la conexión con la base de datos utilizando las credenciales de nuestra app
     $connectionOptions = array('driver' => 'pdo_mysql', 'user' => $db["default"]["username"], 'password' => $db["default"]["password"], 'host' => $db["default"]["hostname"], 'dbname' => $db["default"]["database"]);
     // Creamos el EntityManager
     $this->em = EntityManager::create($connectionOptions, $config);
 }
 public function __construct()
 {
     // load database configuration from CodeIgniter
     require_once APPPATH . 'config/database.php';
     $doctrineClassLoader = new ClassLoader('Doctrine', APPPATH . 'libraries');
     $doctrineClassLoader->register();
     $entitiesClassLoader = new ClassLoader('models', rtrim(APPPATH, "/"));
     $entitiesClassLoader->register();
     $proxiesClassLoader = new ClassLoader('Proxies', APPPATH . 'models/proxies');
     $proxiesClassLoader->register();
     // Set up caches
     $config = new Configuration();
     $cache = new ArrayCache();
     $config->setMetadataCacheImpl($cache);
     $reader = new AnnotationReader();
     $driverImpl = new AnnotationDriver($reader, array(APPPATH . "models/Entities"));
     $config->setMetadataDriverImpl($driverImpl);
     $config->setQueryCacheImpl($cache);
     // Proxy configuration
     $config->setProxyDir(APPPATH . '/models/proxies');
     $config->setProxyNamespace('Proxies');
     $config->setAutoGenerateProxyClasses(true);
     AnnotationRegistry::registerLoader('class_exists');
     // 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);
 }
 protected function _initDoctrine()
 {
     $config = new Configuration();
     switch (APPLICATION_ENV) {
         case 'production':
         case 'staging':
             $cache = new \Doctrine\Common\Cache\ApcCache();
             break;
             // Both development and test environments will use array cache.
         // Both development and test environments will use array cache.
         default:
             $cache = new \Doctrine\Common\Cache\ArrayCache();
             break;
     }
     $config->setMetadataCacheImpl($cache);
     $driverImpl = $config->newDefaultAnnotationDriver(APPLICATION_PATH . '/models');
     $config->setMetadataDriverImpl($driverImpl);
     $config->setQueryCacheImpl($cache);
     $config->setProxyDir(APPLICATION_PATH . '/proxies');
     $config->setProxyNamespace('D2Test\\Proxies');
     $options = $this->getOption('doctrine');
     $config->setAutoGenerateProxyClasses($options['auto_generate_proxy_class']);
     $em = EntityManager::create($options['db'], $config);
     Zend_Registry::set('EntityManager', $em);
     return $em;
 }
 public function __construct()
 {
     if (defined('FCPATH')) {
         //Get CI instance
         $this->ci = CI_Controller::get_instance();
         //Load database configuration from CodeIgniter
         $this->db = $this->ci->db;
         //Database connection information
         $connectionOptions = array('user' => $this->db->username, 'password' => $this->db->password, 'host' => $this->db->hostname, 'dbname' => $this->db->database);
     } elseif (ENVIRONMENT === 'development') {
         include_once str_replace("/", DIRECTORY_SEPARATOR, APPPATH) . 'config' . DIRECTORY_SEPARATOR . 'development' . DIRECTORY_SEPARATOR . 'database.php';
         $connectionOptions = array('user' => $db['default']['username'], 'password' => $db['default']['password'], 'host' => $db['default']['hostname'], 'dbname' => $db['default']['database']);
     }
     $connectionOptions['driver'] = 'pdo_mysql';
     $connectionOptions['charset'] = 'utf8';
     $connectionOptions['driverOptions'] = array(1002 => 'SET NAMES utf8');
     $config = new Configuration();
     //Set up caches
     $cache = new ArrayCache();
     $config->setMetadataCacheImpl($cache);
     $config->setQueryCacheImpl($cache);
     //Set up Annotation
     $driverImpl = $config->newDefaultAnnotationDriver(array(APPPATH . 'models/Entities'));
     $config->setMetadataDriverImpl($driverImpl);
     //Proxy configuration
     $config->setProxyDir(APPPATH . '/models/proxies');
     $config->setProxyNamespace('Proxies');
     $config->setAutoGenerateProxyClasses(TRUE);
     // Create EntityManager
     $this->em = EntityManager::create($connectionOptions, $config);
     //Fix the problem: "unknown database type enum requested"
     $platform = $this->em->getConnection()->getDatabasePlatform();
     $platform->registerDoctrineTypeMapping('enum', 'string');
 }
 public function register(Application $app)
 {
     //Load Doctrine Configuration
     $app['db.configuration'] = $app->share(function () use($app) {
         AnnotationRegistry::registerAutoloadNamespace("Doctrine\\ORM\\Mapping", __DIR__ . '/../../../../../doctrine/orm/lib');
         $config = new ORMConfiguration();
         $cache = $app['debug'] == false ? new ApcCache() : new ArrayCache();
         $config->setMetadataCacheImpl($cache);
         $config->setQueryCacheImpl($cache);
         $chain = new DriverChain();
         foreach ((array) $app['db.orm.entities'] as $entity) {
             switch ($entity['type']) {
                 case 'annotation':
                     $reader = new AnnotationReader();
                     $driver = new AnnotationDriver($reader, (array) $entity['path']);
                     $chain->addDriver($driver, $entity['namespace']);
                     break;
                     /*case 'yml':
                           $driver = new YamlDriver((array)$entity['path']);
                           $driver->setFileExtension('.yml');
                           $chain->addDriver($driver, $entity['namespace']);
                           break;
                       case 'xml':
                           $driver = new XmlDriver((array)$entity['path'], $entity['namespace']);
                           $driver->setFileExtension('.xml');
                           $chain->addDriver($driver, $entity['namespace']);
                           break;*/
                 /*case 'yml':
                       $driver = new YamlDriver((array)$entity['path']);
                       $driver->setFileExtension('.yml');
                       $chain->addDriver($driver, $entity['namespace']);
                       break;
                   case 'xml':
                       $driver = new XmlDriver((array)$entity['path'], $entity['namespace']);
                       $driver->setFileExtension('.xml');
                       $chain->addDriver($driver, $entity['namespace']);
                       break;*/
                 default:
                     throw new \InvalidArgumentException(sprintf('"%s" is not a recognized driver', $type));
                     break;
             }
         }
         $config->setMetadataDriverImpl($chain);
         $config->setProxyDir($app['db.orm.proxies_dir']);
         $config->setProxyNamespace($app['db.orm.proxies_namespace']);
         $config->setAutoGenerateProxyClasses($app['db.orm.auto_generate_proxies']);
         return $config;
     });
     //Set Defaut Configuration
     $defaults = array('entities' => array(array('type' => 'annotation', 'path' => 'Entity', 'namespace' => 'Entity')), 'proxies_dir' => 'cache/doctrine/Proxy', 'proxies_namespace' => 'DoctrineProxy', 'auto_generate_proxies' => true);
     foreach ($defaults as $key => $value) {
         if (!isset($app['db.orm.' . $key])) {
             $app['db.orm.' . $key] = $value;
         }
     }
     $self = $this;
     $app['db.orm.em'] = $app->share(function () use($self, $app) {
         return EntityManager::create($app['db'], $app['db.configuration']);
     });
 }
 /**
  * Creates a new EntityManager instance based on the provided configuration.
  *
  *     $factory = new Doctrine_EMFactory;
  *     $em = $factory->entity_manager();
  *
  * @param string $db_group the name of the Kohana database config group to get connection information from
  *
  * @return \Doctrine\ORM\EntityManager
  */
 public function entity_manager($db_group = 'default')
 {
     $config = $this->config->load('doctrine');
     // Ensure the composer autoloader is registered
     require_once $config['composer_vendor_path'] . 'autoload.php';
     // Create the Configuration class
     $orm_config = new Configuration();
     // Create the metadata driver
     $driver = $this->create_annotation_driver();
     $orm_config->setMetadataDriverImpl($driver);
     // Configure the proxy directory and namespace
     $orm_config->setProxyDir($config['proxy_dir']);
     $orm_config->setProxyNamespace($config['proxy_namespace']);
     if ($config->get('use_underscore_naming_strategy')) {
         $naming_strategy = new UnderscoreNamingStrategy($config->get('case_underscore_naming_strategy'));
         $orm_config->setNamingStrategy($naming_strategy);
     }
     // Configure environment-specific options
     if ($this->environment === Kohana::DEVELOPMENT) {
         $orm_config->setAutoGenerateProxyClasses(TRUE);
         $cache = new ArrayCache();
     } else {
         $orm_config->setAutoGenerateProxyClasses(FALSE);
         $cache = new ApcCache();
     }
     // Set the cache drivers
     $orm_config->setMetadataCacheImpl($cache);
     $orm_config->setQueryCacheImpl($cache);
     // Create the Entity Manager with the database connection information
     $em = EntityManager::create($this->get_connection_config($db_group), $orm_config);
     $this->register_custom_types($config);
     return $em;
 }
 public function __construct()
 {
     // load database configuration from CodeIgniter
     require_once APPPATH . 'config/database.php';
     //A Doctrine Autoloader is needed to load the models
     $entitiesClassLoader = new ClassLoader('Entity', APPPATH . "models");
     $entitiesClassLoader->register();
     // Set up caches
     $config = new Configuration();
     $cache = new ArrayCache();
     $config->setMetadataCacheImpl($cache);
     AnnotationRegistry::registerFile(APPPATH . "vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php");
     $reader = new AnnotationReader();
     $driverImpl = new \Doctrine\ORM\Mapping\Driver\AnnotationDriver($reader, array(APPPATH . 'models/Entity'));
     $config->setMetadataDriverImpl($driverImpl);
     $config->setQueryCacheImpl($cache);
     $config->setQueryCacheImpl($cache);
     // Proxy configuration
     $config->setProxyDir(APPPATH . 'models/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' => 'root', 'password' => 'whoami', 'host' => 'localhost', 'dbname' => 'pms3');
     // Create EntityManager
     $this->em = EntityManager::create($connectionOptions, $config);
 }
Beispiel #14
0
 /**
  * Init the doctrine entity manager.
  *
  * @return Doctrine\ORM\EntityManager
  */
 private function _initEntityManager()
 {
     // New database configuration
     $config = new Configuration();
     $driverImpl = $config->newDefaultAnnotationDriver();
     $config->setMetadataDriverImpl($driverImpl);
     $proxiesPath = $this->_application->getCacheDir() . DIRECTORY_SEPARATOR . 'Proxies';
     $config->setProxyDir($proxiesPath);
     $config->setProxyNamespace('Proxies');
     // Create EntityManager
     $em = EntityManager::create($this->_config, $config);
     if (isset($this->_config['charset'])) {
         try {
             $em->getConnection()->executeUpdate('SET SESSION character_set_client = "' . addslashes($this->_config['charset']) . '";');
             $em->getConnection()->executeUpdate('SET SESSION character_set_connection = "' . addslashes($this->_config['charset']) . '";');
             $em->getConnection()->executeUpdate('SET SESSION character_set_results = "' . addslashes($this->_config['charset']) . '";');
         } catch (\Exception $e) {
             throw new BBException(sprintf('Invalid database character set `%s`', $this->_config['charset']), BBException::INVALID_ARGUMENT, $e);
         }
     }
     if (isset($this->_config['collation'])) {
         try {
             $em->getConnection()->executeUpdate('SET SESSION collation_connection = "' . addslashes($this->_config['collation']) . '";');
         } catch (\Exception $e) {
             throw new BBException(sprintf('Invalid database collation `%s`', $this->_config['collation']), BBException::INVALID_ARGUMENT, $e);
         }
     }
     return $em;
 }
Beispiel #15
0
 public function loadDependencyDefaults(ContainerInterface $container)
 {
     // logger
     $container['logger'] = function (ContainerInterface $c) {
         $settings = $c->get('settings')['logger'];
         $debug = array_key_exists('debug', $settings) && $settings['debug'];
         $logger = new Logger($settings['name']);
         $logger->pushProcessor(new UidProcessor());
         $logger->pushHandler(new StreamHandler($settings['path'], $debug ? Logger::DEBUG : Logger::ERROR));
         return $logger;
     };
     // entity manager
     $container['entityManager'] = function (ContainerInterface $c) {
         $settings = $c->get('settings')['database'];
         $config = new Configuration();
         $config->setMetadataCacheImpl(new ArrayCache());
         $driverImpl = $config->newDefaultAnnotationDriver(array(__DIR__ . '/Entity'));
         $config->setMetadataDriverImpl($driverImpl);
         $config->setProxyDir(__DIR__ . '/Entity/Proxy');
         $config->setProxyNamespace('Proxy');
         return EntityManager::create($settings, $config);
     };
     $container['foundHandler'] = function () {
         return new RequestResponseArgs();
     };
     $container['dataFormatter'] = function () {
         return new ResponseDataFormatter();
     };
     return $container;
 }
Beispiel #16
0
 public function __construct()
 {
     //Set up class loading. You cold use different autoloaders, provider by your
     //if you want to.
     require_once APPPATH . 'third_party/DoctrineORM-2.2.2/libraries/Doctrine/Common/ClassLoader.php';
     require_once APPPATH . 'third_party/DoctrineORM-2.2.2/libraries/Doctrine/ORM/Tools/Setup.php';
     Doctrine\ORM\Tools\Setup::registerAutoloadDirectory(APPPATH . 'third_party/DoctrineORM-2.2.2/libraries/');
     $doctrineClassLoader = new ClassLoader('Doctrine', APPPATH . 'third_party/DoctrineORM-2.2.2/libraries');
     $doctrineClassLoader->register();
     $proxiesClassLoader = new ClassLoader('Proxies', APPPATH . 'models/proxies');
     $proxiesClassLoader->register();
     //Set up caches
     $config = new Configuration();
     $cache = new ArrayCache();
     $config->setMetadataCacheImpl($cache);
     $driverImpl = $config->newDefaultAnnotationDriver([APPPATH . 'models/Entities']);
     $config->setMetadataDriverImpl($driverImpl);
     $config->setQueryCacheImpl($cache);
     //Proxy configuration
     $config->setProxyDir(APPPATH . '/models/proxies');
     $config->setProxyNamespace('Proxies');
     //Set up logger
     //$logger = new EchoSQLLogger;
     //$config->setSQLLogger($logger);
     $config->setAutoGenerateProxyClasses(true);
     include APPPATH . 'config/database.php';
     //Database connection information
     $connectionOptions = ['driver' => 'pdo_mysql', 'user' => $db['default']['username'], 'password' => $db['default']['password'], 'host' => $db['default']['hostname'], 'dbname' => $db['default']['database'], 'charset' => $db['default']['char_set'], 'driverOptions' => [1002 => 'SET NAMES utf8']];
     //Enforce connection character set. This is very important if you are
     //using MySQL and InnoDB tables!
     //Doctrine_Manager::connection()->setCharset('utf8');
     //Doctrine_Manager::connection()->setCollate('utf8_general_ci');
     //Create EntityManager
     $this->em = EntityManager::create($connectionOptions, $config);
 }
Beispiel #17
0
 public function __construct()
 {
     // load database configuration from CodeIgniter
     if (!file_exists($file_path = APPPATH . 'config/' . ENVIRONMENT . '/database.php') && !file_exists($file_path = APPPATH . 'config/database.php')) {
         throw new Exception('The configuration file database.php does not exist.');
     }
     require $file_path;
     $entitiesClassLoader = new ClassLoader('models', rtrim(APPPATH, "/"));
     $entitiesClassLoader->register();
     $proxiesClassLoader = new ClassLoader('Proxies', APPPATH . 'models/Proxies');
     $proxiesClassLoader->register();
     // Set up caches
     $config = new Configuration();
     $cache = new ArrayCache();
     $config->setMetadataCacheImpl($cache);
     $driverImpl = $config->newDefaultAnnotationDriver(array(APPPATH . 'models/Entities'));
     $config->setMetadataDriverImpl($driverImpl);
     $config->setQueryCacheImpl($cache);
     $config->setQueryCacheImpl($cache);
     // Proxy configuration
     $config->setProxyDir(APPPATH . '/models/Proxies');
     $config->setProxyNamespace('Proxies');
     // Set up logger
     $logger = new EchoSQLLogger();
     $config->setSQLLogger($logger);
     $config->setAutoGenerateProxyClasses(true);
     // Database connection information
     $connectionOptions = $this->convertDbConfig($db['default']);
     // Create EntityManager
     $this->em = EntityManager::create($connectionOptions, $config);
 }
Beispiel #18
0
 /**
  * Connect and set-up Doctrine
  *
  * @return void
  */
 public function connect()
 {
     $this->configuration = new \Doctrine\ORM\Configuration();
     // Setup cache
     $this->setDoctrineCache();
     // Set metadata driver
     $chain = new \Doctrine\ORM\Mapping\Driver\DriverChain();
     $chain->addDriver($this->createAnnotationDriver(LC_DIR_CACHE_MODEL), 'XLite\\Model');
     $iterator = new \RecursiveDirectoryIterator(LC_DIR_CACHE_CLASSES . 'XLite' . LC_DS . 'Module', \FilesystemIterator::SKIP_DOTS);
     foreach ($iterator as $dir) {
         if (\Includes\Utils\FileManager::isDir($dir->getPathName())) {
             $iterator2 = new \RecursiveDirectoryIterator($dir->getPathName(), \FilesystemIterator::SKIP_DOTS);
             foreach ($iterator2 as $dir2) {
                 if (\Includes\Utils\FileManager::isDir($dir2->getPathName()) && \Includes\Utils\FileManager::isDir($dir2->getPathName() . LC_DS . 'Model')) {
                     $chain->addDriver($this->createAnnotationDriver($dir2->getPathName() . LC_DS . 'Model'), 'XLite\\Module\\' . $dir->getBaseName() . '\\' . $dir2->getBaseName() . '\\Model');
                 }
             }
         }
     }
     $this->configuration->setMetadataDriverImpl($chain);
     // Set proxy settings
     $this->configuration->setProxyDir(rtrim(LC_DIR_CACHE_PROXY, LC_DS));
     $this->configuration->setProxyNamespace(LC_MODEL_PROXY_NS);
     $this->configuration->setAutoGenerateProxyClasses(false);
     // Register custom functions
     $this->configuration->addCustomStringFunction('if', '\\XLite\\Core\\Doctrine\\IfFunction');
     $this->tablePrefix = \XLite::getInstance()->getOptions(array('database_details', 'table_prefix'));
     // Initialize DB connection and entity manager
     $this->startEntityManager();
 }
 /**
  * @param  ContainerInterface $container
  * @return EntityManager
  */
 public function __invoke(ContainerInterface $container)
 {
     $config = $container->has('config') ? $container->get('config') : [];
     if (!isset($config['doctrine'])) {
         throw new ServiceNotCreatedException('Missing Doctrine configuration');
     }
     $config = $config['doctrine'];
     $proxyDir = isset($config['proxy_dir']) ? $config['proxy_dir'] : 'data/DoctrineORM/Proxy';
     $proxyNamespace = isset($config['proxy_namespace']) ? $config['proxy_namespace'] : 'DoctrineORM/Proxy';
     $autoGenerateProxyClasses = isset($config['configuration']['auto_generate_proxy_classes']) ? $config['configuration']['auto_generate_proxy_classes'] : false;
     $underscoreNamingStrategy = isset($config['configuration']['underscore_naming_strategy']) ? $config['configuration']['underscore_naming_strategy'] : false;
     // Doctrine ORM
     $doctrine = new Configuration();
     $doctrine->setProxyDir($proxyDir);
     $doctrine->setProxyNamespace($proxyNamespace);
     $doctrine->setAutoGenerateProxyClasses($autoGenerateProxyClasses);
     // Naming Strategy
     if ($underscoreNamingStrategy) {
         $doctrine->setNamingStrategy(new UnderscoreNamingStrategy());
     }
     // ORM mapping by Annotation
     //AnnotationRegistry::registerAutoloadNamespace($config['driver']['annotations']['class']);
     AnnotationRegistry::registerFile('vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php');
     $driver = new AnnotationDriver(new AnnotationReader(), $config['driver']['annotations']['paths']);
     $doctrine->setMetadataDriverImpl($driver);
     // Cache
     $cache = $container->get(\Doctrine\Common\Cache\Cache::class);
     $doctrine->setQueryCacheImpl($cache);
     $doctrine->setResultCacheImpl($cache);
     $doctrine->setMetadataCacheImpl($cache);
     // EntityManager
     return EntityManager::create($config['connection']['orm_default']['params'], $doctrine);
 }
Beispiel #20
0
 /**
  * @param array $settings
  * @param bool $debug
  * @return EntityManager
  * @throws \Doctrine\ORM\ORMException
  */
 public static function factory($settings, $debug = true)
 {
     if ($debug || !function_exists('apc_fetch')) {
         $cache = new ArrayCache();
     } else {
         $cache = new ApcCache();
     }
     $dbSettings = $settings['doctrine'];
     $config = new Configuration();
     $config->setMetadataCacheImpl($cache);
     // Do not use default Annotation driver
     $driverImpl = new AnnotationDriver(new AnnotationReader(), $dbSettings['entities']);
     // Allow all annotations
     AnnotationRegistry::registerLoader('class_exists');
     $config->setMetadataDriverImpl($driverImpl);
     $config->setQueryCacheImpl($cache);
     $config->setProxyDir($dbSettings['proxy_path']);
     $config->setProxyNamespace('Zaralab\\Doctrine\\Proxies');
     if ($debug) {
         $config->setAutoGenerateProxyClasses(true);
     } else {
         $config->setAutoGenerateProxyClasses(false);
     }
     $connectionOptions = $dbSettings['dbal'];
     return EntityManager::create($connectionOptions, $config);
 }
 /**
  * @return \Doctrine\ORM\EntityManager
  */
 protected function createEntityManager()
 {
     // event manager used to create schema before tests
     $eventManager = new EventManager();
     $eventManager->addEventListener(array("preTestSetUp"), new SchemaSetupListener());
     // doctrine xml configs and namespaces
     $configPathList = array();
     if (is_dir(__DIR__ . '/../Resources/config/doctrine')) {
         $dir = __DIR__ . '/../Resources/config/doctrine';
         $configPathList[] = $dir;
         $prefixList[$dir] = 'Kitpages\\DataGridBundle\\Entities';
     }
     if (is_dir(__DIR__ . '/_doctrine/config')) {
         $dir = __DIR__ . '/_doctrine/config';
         $configPathList[] = $dir;
         $prefixList[$dir] = 'Kitpages\\DataGridBundle\\Tests\\TestEntities';
     }
     // create drivers (that reads xml configs)
     $driver = new \Symfony\Bridge\Doctrine\Mapping\Driver\XmlDriver($configPathList);
     $driver->setNamespacePrefixes($prefixList);
     // create config object
     $config = new Configuration();
     $config->setMetadataCacheImpl(new ArrayCache());
     $config->setMetadataDriverImpl($driver);
     $config->setProxyDir(__DIR__ . '/TestProxies');
     $config->setProxyNamespace('Kitpages\\DataGridBundle\\Tests\\TestProxies');
     $config->setAutoGenerateProxyClasses(true);
     //$config->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger());
     // create entity manager
     $em = EntityManager::create(array('driver' => 'pdo_sqlite', 'path' => "/tmp/sqlite-test.db"), $config, $eventManager);
     return $em;
 }
Beispiel #22
0
 public static function createEntityManager($database)
 {
     $config = new Doctrine\ORM\Configuration();
     // annotations
     $annotationDriver = $config->newDefaultAnnotationDriver(array(APP_DIR . '/Model', NEURON_DIR . '/Model'));
     $config->setMetadataDriverImpl($annotationDriver);
     // proxy
     $config->setProxyNamespace('Neuron\\Proxy');
     $config->setProxyDir(TEMP_DIR);
     // cache
     $cache = Environment::isProduction() ? new NetteDoctrineCache() : new Doctrine\Common\Cache\ArrayCache();
     $config->setMetadataCacheImpl($cache);
     $config->setQueryCacheImpl($cache);
     // debugbar
     $config->setSQLLogger(Doctrine2Panel::getAndRegister());
     // entity manager
     $em = Doctrine\ORM\EntityManager::create((array) $database, $config);
     $evm = $em->getEventManager();
     $evm->addEventSubscriber(new Doctrine\DBAL\Event\Listeners\MysqlSessionInit("utf8", "utf8_czech_ci"));
     $evm->addEventSubscriber(new ValidationSubscriber());
     $evm->addEventSubscriber(new CacheSubscriber());
     $neonParser = new \Nette\NeonParser();
     $aliases = $neonParser->parse(file_get_contents(APP_DIR . "/entityClassAliases.neon"));
     $evm->addEventSubscriber(new \Neuron\Model\Doctrine\EntityClassAliasesSubscriber($aliases));
     return $em;
 }
 public function __construct(array $dbConfig, array $options = array())
 {
     extract($options);
     $entityClassLoader = new ClassLoader("Entities", $entityPath);
     $entityClassLoader->register();
     $proxyPath = isset($proxyPath) ? $proxyPath : $entityPath;
     $proxyClassLoader = new ClassLoader("Proxies", $proxyPath);
     $proxyClassLoader->register();
     $config = new Configuration();
     if ($isDevMode || $isArrayCache) {
         $cache = new ArrayCache();
     } else {
         $cache = new ApcCache();
     }
     $config->setMetadataCacheImpl($cache);
     $config->setQueryCacheImpl($cache);
     $config->setProxyDir($proxyPath);
     $config->setProxyNamespace($namespaces["proxy"]);
     if (isset($isDevMode) && $isDevMode) {
         $config->setAutogenerateProxyClasses(true);
     }
     if (isset($driverClass) && class_exists($driverClass)) {
         $annotationDriver = new $driverClass($entity_driver);
     } else {
         $annotationDriver = new AnnotationDriver(new AnnotationReader(), array($entityPath));
         AnnotationRegistry::registerLoader('class_exists');
     }
     $config->setMetadataDriverImpl($annotationDriver);
     $this->setEntityManager($dbConfig, $config);
 }
Beispiel #24
0
 public function _initDoctrineEntityManager()
 {
     $this->bootstrap(array('classLoaders'));
     $zendConfig = $this->getOptions();
     // parameters required for connecting to the database.
     // the required attributes are driver, host, user, password and dbname
     $connectionParameters = $zendConfig['doctrine']['connectionParameters'];
     // 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);
     return $entityManager;
 }
 public function __construct()
 {
     // load database configuration from CodeIgniter
     require_once APPPATH . 'config/development/database.php';
     // Set up class loading. You could use different autoloaders, provided by your favorite framework,
     // if you want to.
     require_once APPPATH . 'libraries/Doctrine/Common/ClassLoader.php';
     $doctrineClassLoader = new ClassLoader('Doctrine', APPPATH . 'libraries');
     $doctrineClassLoader->register();
     $entitiesClassLoader = new ClassLoader('models', rtrim(APPPATH, "/"));
     $entitiesClassLoader->register();
     $proxiesClassLoader = new ClassLoader('Proxies', APPPATH . 'models/proxies');
     $proxiesClassLoader->register();
     // Set up caches
     $config = new Configuration();
     $cache = new ArrayCache();
     $config->setMetadataCacheImpl($cache);
     $driverImpl = $config->newDefaultAnnotationDriver(array(APPPATH . 'models/Entities'));
     $config->setMetadataDriverImpl($driverImpl);
     $config->setQueryCacheImpl($cache);
     $config->setQueryCacheImpl($cache);
     // Proxy configuration
     $config->setProxyDir(APPPATH . '/models/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);
 }
 protected function setUp()
 {
     $config = new Configuration();
     //$config->setHydratorDir(sys_get_temp_dir());
     //$config->setHydratorNamespace('Hydrators');
     $config->setProxyDir(sys_get_temp_dir());
     $config->setProxyNamespace('Proxies');
     $locatorXml = new SymfonyFileLocator(array(__DIR__ . '/../../../../../lib/Vespolina/Product/Mapping' => 'Vespolina\\Entity\\Product', __DIR__ . '/../../../../../vendor/vespolina/pricing/lib/Vespolina/Pricing/Mapping' => 'Vespolina\\Entity\\Pricing', __DIR__ . '/../../../../../vendor/vespolina/taxonomy/lib/Vespolina/Taxonomy/Mapping' => 'Vespolina\\Entity\\Taxonomy'), '.orm.xml');
     $drivers = new MappingDriverChain();
     $xmlDriver = new XmlDriver($locatorXml);
     $config->setMetadataDriverImpl($xmlDriver);
     $config->setMetadataCacheImpl(new ArrayCache());
     $config->setAutoGenerateProxyClasses(true);
     $eventManager = new EventManager();
     $treeListener = new TreeListener();
     $eventManager->addEventSubscriber($treeListener);
     $em = EntityManager::create(array('driver' => 'pdo_sqlite', 'path' => 'database.sqlite'), $config, $eventManager);
     $schemaTool = new \Doctrine\ORM\Tools\SchemaTool($em);
     $classes = array($em->getClassMetadata('Vespolina\\Entity\\Product\\Product'), $em->getClassMetadata('Vespolina\\Entity\\Taxonomy\\TaxonomyNode'));
     try {
         $schemaTool->dropSchema(array());
         $schemaTool->createSchema($classes);
     } catch (\Exception $e) {
     }
     $this->productGateway = new ProductDoctrineORMGateway($em, 'Vespolina\\Entity\\Product\\Product');
     $this->taxonomyGateway = new TaxonomyDoctrineORMGateway($em, 'Vespolina\\Entity\\Taxonomy\\TaxonomyNode');
     parent::setUp();
 }
Beispiel #27
0
 public function register()
 {
     $this->container['object_manager'] = function () {
         $development = false;
         if (defined('ENVIRONMENT') && ENVIRONMENT === 'development') {
             $development = true;
         }
         $config = new Configuration();
         if ($development) {
             $cache = new ArrayCache();
         } else {
             $cache = new ApcCache();
         }
         $config->setMetadataCacheImpl($cache);
         $mappings = $this->container->get('config')['orm']['mappings'];
         $config->setMetadataDriverImpl(new XmlDriver($mappings));
         $proxyDir = $this->container->get('config')['orm']['proxy_dir'];
         $config->setProxyDir($proxyDir);
         $config->setQueryCacheImpl($cache);
         $config->setProxyNamespace('Jirro\\ORM\\Proxies');
         if ($development) {
             $config->setAutoGenerateProxyClasses(true);
         } else {
             $config->setAutoGenerateProxyClasses(false);
         }
         $dbConnection = $this->container->get('db_connection');
         $objectManager = ObjectManager::create($dbConnection, $config);
         return $objectManager;
     };
     $this->container->inflector('Jirro\\Component\\ORM\\ObjectManagerAwareInterface')->invokeMethod('setObjectManager', ['object_manager']);
 }
 public function __construct($config)
 {
     if (isset($config["doctrine"])) {
         $dbParams = $config["doctrine"]["db_params"];
         $paths = StringCommon::replaceKeyWords($config["doctrine"]["entity_paths"]);
         $isDevMode = $config["doctrine"]["is_dev_mode"];
         $proxyDir = StringCommon::replaceKeyWords($config["doctrine"]["proxy_dir"]);
         $proxyNamespace = $config["doctrine"]["proxy_namespace"];
         $applicationMode = Game::getInstance()->getApplicationMode();
         if ($applicationMode == Game::DEVELOPMENT_MODE) {
             $cache = new \Doctrine\Common\Cache\ArrayCache();
         } else {
             $cache = new \Doctrine\Common\Cache\ApcCache();
         }
         $doctrineConfig = new Configuration();
         $doctrineConfig->setMetadataCacheImpl($cache);
         $driverImpl = $doctrineConfig->newDefaultAnnotationDriver($paths);
         $doctrineConfig->setMetadataDriverImpl($driverImpl);
         $doctrineConfig->setQueryCacheImpl($cache);
         $doctrineConfig->setProxyDir($proxyDir);
         $doctrineConfig->setProxyNamespace($proxyNamespace);
         if ($applicationMode == Game::DEVELOPMENT_MODE) {
             $doctrineConfig->setAutoGenerateProxyClasses(true);
         } else {
             $doctrineConfig->setAutoGenerateProxyClasses(false);
         }
         $entityManager = EntityManager::create($dbParams, $doctrineConfig);
         Game::getInstance()->getContainer()->set("entity_manager", $entityManager);
     } else {
         throw new \RuntimeException("You need add Doctrine config in your res/config.yml");
     }
 }
Beispiel #29
0
 public function __construct()
 {
     $this->setRoot("/var/www/html/uan/");
     $this->setEntidade(array($this->getRoot() . "models/"));
     $this->setIsDevMode(true);
     $mode = "DESENVOLVIMENTO";
     $config = Setup::createAnnotationMetadataConfiguration($this->getEntidade(), $this->getIsDevMode(), NULL, NULL, FALSE);
     if ($mode == "DESENVOLVIMENTO") {
         $cache = new \Doctrine\Common\Cache\ArrayCache();
     } else {
         $cache = new \Doctrine\Common\Cache\ApcCache();
     }
     $config = new Configuration();
     $config->setMetadataCacheImpl($cache);
     $driverImpl = $config->newDefaultAnnotationDriver($this->getRoot() . 'models/');
     $config->setMetadataDriverImpl($driverImpl);
     $config->setQueryCacheImpl($cache);
     $config->setProxyDir($this->getRoot() . 'proxies/');
     $config->setProxyNamespace('proxies');
     if ($mode == "DESENVOLVIMENTO") {
         $config->setAutoGenerateProxyClasses(true);
     } else {
         $config->setAutoGenerateProxyClasses(false);
     }
     $config = Setup::createAnnotationMetadataConfiguration($this->getEntidade(), $this->getIsDevMode(), NULL, NULL, FALSE);
     $dbParams = array('driver' => 'pdo_mysql', 'user' => 'root', 'password' => '', 'dbname' => 'ceafie', 'charset' => 'utf8', 'driverOptions' => array(1002 => 'SET NAMES utf8'));
     $this->em = EntityManager::create($dbParams, $config);
     $loader = new ClassLoader('Entity', __DIR__ . '/models');
     $loader->register();
 }
Beispiel #30
0
 public function __construct()
 {
     // load database configuration from CodeIgniter
     require_once APPPATH . 'config/database.php';
     // Set up class loading. You could use different autoloaders, provided by your favorite framework,
     // if you want to.
     //require_once APPPATH.'libraries/Doctrine/Common/ClassLoader.php';
     // We use the Composer Autoloader instead - just set
     // $config['composer_autoload'] = TRUE; in application/config/config.php
     //require_once APPPATH.'vendor/autoload.php';
     //A Doctrine Autoloader is needed to load the models
     $entitiesClassLoader = new ClassLoader('Entities', APPPATH . "models");
     $entitiesClassLoader->register();
     // Set up caches
     $config = new Configuration();
     $cache = new ArrayCache();
     $config->setMetadataCacheImpl($cache);
     $driverImpl = $config->newDefaultAnnotationDriver(array(APPPATH . 'models/Entities'));
     $config->setMetadataDriverImpl($driverImpl);
     $config->setQueryCacheImpl($cache);
     $config->setQueryCacheImpl($cache);
     // Proxy configuration
     $config->setProxyDir(APPPATH . '/models/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' => 'dev_pila', 'password' => 'damienludothomas', 'host' => 'localhost', 'dbname' => 'tradr');
     // Create EntityManager
     $this->em = EntityManager::create($connectionOptions, $config);
 }