Example #1
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);
     }
 }
 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);
 }
 /**
  * {@inheritdoc}
  */
 public function register(Container $app)
 {
     //  @todo crear DoctrineOrmManagerRegistryProvider
     //  o poner en boot estos servicios
     $app->extend('form.extensions', function ($extensions, $app) {
         $extensions[] = new DoctrineOrmExtension($app['doctrine']);
         return $extensions;
     });
     $app['doctrine.orm.validator.unique_validator'] = function ($app) {
         return new UniqueEntityValidator($app['doctrine']);
     };
     if (!isset($app['validator.validator_service_ids'])) {
         $app['validator.validator_service_ids'] = [];
     }
     $app['validator.validator_service_ids'] = array_merge($app['validator.validator_service_ids'], ['doctrine.orm.validator.unique' => 'doctrine.orm.validator.unique_validator']);
     $app->extend('validator.object_initializers', function (array $objectInitializers, $app) {
         $objectInitializers[] = new DoctrineInitializer($app['doctrine']);
         return $objectInitializers;
     });
     $app['doctrine'] = function ($app) {
         return new ManagerRegistry($app);
     };
     $app['orm.em'] = function ($app) {
         $em = EntityManager::create($app['db'], $app['orm.config'], $app['db.event_manager']);
         return $em;
     };
     // Entity manager alias
     $app['em'] = function ($app) {
         return $app['orm.em'];
     };
     $app['orm.config'] = function ($app) {
         $config = new Configuration();
         // @todo path!
         $config->setProxyDir(sprintf('%s/../../../../../../var/cache/doctrine/proxies', __DIR__));
         $config->setProxyNamespace('DoctrineProxies');
         $config->setAutoGenerateProxyClasses($app['debug']);
         // The strongly recommended FALSE in production
         $chain = new MappingDriverChain();
         // Pulsar
         $path = realpath(sprintf('%s/../Entity', __DIR__));
         $driver = $config->newDefaultAnnotationDriver((array) $path, false);
         $chain->addDriver($driver, 'Pulsar\\Entity');
         // App
         $path = realpath(sprintf('%s/../../../../../../src/App', __DIR__));
         $driver = $config->newDefaultAnnotationDriver((array) $path, false);
         $chain->addDriver($driver, 'App\\Entity');
         $config->setMetadataCacheImpl($app['orm.cache']);
         $config->setMetadataDriverImpl($chain);
         return $config;
     };
     $app['orm.cache'] = function () {
         return new ArrayCache();
     };
 }
Example #4
0
 public function testNewDefaultAnnotationDriver()
 {
     $paths = array(__DIR__);
     $reflectionClass = new ReflectionClass(__NAMESPACE__ . '\\ConfigurationTestAnnotationReaderChecker');
     $annotationDriver = $this->configuration->newDefaultAnnotationDriver($paths, false);
     $reader = $annotationDriver->getReader();
     $annotation = $reader->getMethodAnnotation($reflectionClass->getMethod('namespacedAnnotationMethod'), 'Doctrine\\ORM\\Mapping\\PrePersist');
     $this->assertInstanceOf('Doctrine\\ORM\\Mapping\\PrePersist', $annotation);
     $annotationDriver = $this->configuration->newDefaultAnnotationDriver($paths);
     $reader = $annotationDriver->getReader();
     $annotation = $reader->getMethodAnnotation($reflectionClass->getMethod('simpleAnnotationMethod'), 'Doctrine\\ORM\\Mapping\\PrePersist');
     $this->assertInstanceOf('Doctrine\\ORM\\Mapping\\PrePersist', $annotation);
 }
 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;
 }
Example #6
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);
 }
Example #7
0
 /**
  * @return EntityManager
  */
 protected function getEntityManager()
 {
     if (null !== $this->em) {
         return $this->em;
     }
     $config = new Configuration();
     $config->setMetadataCacheImpl(new ArrayCache());
     $config->setQueryCacheImpl(new ArrayCache());
     $config->setProxyDir(__DIR__ . '/Proxies');
     $config->setAutoGenerateProxyClasses(ProxyFactory::AUTOGENERATE_EVAL);
     $config->setProxyNamespace('SimpleThings\\EntityAudit\\Tests\\Proxies');
     $config->setMetadataDriverImpl($config->newDefaultAnnotationDriver(array(realpath(__DIR__ . '/Fixtures/Core'), realpath(__DIR__ . '/Fixtures/Issue'), realpath(__DIR__ . '/Fixtures/Relation')), false));
     Gedmo\DoctrineExtensions::registerAnnotations();
     $connection = $this->_getConnection();
     // get rid of more global state
     $evm = $connection->getEventManager();
     foreach ($evm->getListeners() as $event => $listeners) {
         foreach ($listeners as $listener) {
             $evm->removeEventListener(array($event), $listener);
         }
     }
     $this->em = EntityManager::create($connection, $config);
     if (isset($this->customTypes) and is_array($this->customTypes)) {
         foreach ($this->customTypes as $customTypeName => $customTypeClass) {
             if (!Type::hasType($customTypeName)) {
                 Type::addType($customTypeName, $customTypeClass);
             }
             $this->em->getConnection()->getDatabasePlatform()->registerDoctrineTypeMapping('db_' . $customTypeName, $customTypeName);
         }
     }
     return $this->em;
 }
Example #8
0
 public function init()
 {
     $dbParams = ['driver' => $this->driver, 'host' => $this->host, 'user' => $this->user, 'password' => $this->password, 'dbname' => $this->dbname, 'charset' => 'utf8mb4'];
     $this->pathProxy = $this->path . DIRECTORY_SEPARATOR . 'proxy';
     if (!is_dir($this->pathCache)) {
         File::createDirectory($this->pathCache);
     }
     if (!is_dir($this->pathProxy)) {
         File::createDirectory($this->pathProxy);
     }
     $config = new Configuration();
     $cache = new \Doctrine\Common\Cache\FilesystemCache($this->pathCache);
     $config->setMetadataCacheImpl($cache);
     $config->setQueryCacheImpl($cache);
     $driverImpl = $config->newDefaultAnnotationDriver($this->path);
     $config->setMetadataDriverImpl($driverImpl);
     $config->setProxyDir($this->pathProxy);
     $config->setProxyNamespace('app\\tables\\proxy');
     if ($this->applicationMode == "development") {
         $config->setAutoGenerateProxyClasses(true);
     } else {
         $config->setAutoGenerateProxyClasses(false);
     }
     $this->doctrine = EntityManager::create($dbParams, $config);
 }
Example #9
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;
 }
function initDoctrine()
{
    require_once __DIR__ . '/../lib/vendor/doctrine-common/lib/Doctrine/Common/ClassLoader.php';
    // Set up class loading. You could use different autoloaders, provided by your favorite framework,
    // if you want to.
    $classLoader = new ClassLoader('Doctrine\\ORM', realpath(__DIR__ . '/../lib'));
    $classLoader->register();
    $classLoader = new ClassLoader('Doctrine\\DBAL', realpath(__DIR__ . '/../lib/vendor/doctrine-dbal/lib'));
    $classLoader->register();
    $classLoader = new ClassLoader('Doctrine\\Common', realpath(__DIR__ . '/../lib/vendor/doctrine-common/lib'));
    $classLoader->register();
    $classLoader = new ClassLoader('Symfony', realpath(__DIR__ . '/../lib/vendor'));
    $classLoader->register();
    $classLoader = new ClassLoader('Entities', __DIR__);
    $classLoader->register();
    $classLoader = new ClassLoader('Proxies', __DIR__);
    $classLoader->register();
    // Set up caches
    $config = new Configuration();
    $cache = new ApcCache();
    $config->setMetadataCacheImpl($cache);
    $driverImpl = $config->newDefaultAnnotationDriver(array(__DIR__ . "/Entities"));
    $config->setMetadataDriverImpl($driverImpl);
    $config->setQueryCacheImpl($cache);
    // Proxy configuration
    $config->setProxyDir(__DIR__ . '/Proxies');
    $config->setProxyNamespace('Proxies');
    $config->setMetadataCacheImpl(new \Doctrine\Common\Cache\ArrayCache());
    // Database connection information
    $connectionOptions = array('driver' => 'pdo_sqlite', 'path' => __DIR__ . '/database.sqlite');
    // Create EntityManager
    $em = EntityManager::create($connectionOptions, $config);
    return $em;
}
 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);
 }
Example #12
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();
 }
Example #13
0
 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');
 }
Example #14
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($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");
     }
 }
Example #16
0
 private function loadDoctrine($dbname, $host, $username, $password)
 {
     $lib = APPLICATION_PATH . "/doctrine-orm";
     Doctrine\ORM\Tools\Setup::registerAutoloadDirectory($lib);
     if (APPLICATION_ENV == "production") {
         $cache = new \Doctrine\Common\Cache\ApcCache();
     } else {
         $cache = new \Doctrine\Common\Cache\ArrayCache();
     }
     $config = new Configuration();
     $config->setMetadataCacheImpl($cache);
     $driverImpl = $config->newDefaultAnnotationDriver(APPLICATION_PATH . '/modules/default/models');
     $config->setMetadataDriverImpl($driverImpl);
     $config->setQueryCacheImpl($cache);
     $config->setProxyDir(APPLICATION_PATH . '/Proxies');
     $config->setProxyNamespace('EasyCMS\\Proxies');
     if ($applicationMode == "production") {
         $config->setAutoGenerateProxyClasses(false);
     } else {
         $config->setAutoGenerateProxyClasses(true);
     }
     $connectionOptions = array('driver' => 'pdo_mysql', 'dbname' => $dbname, 'user' => $username, 'password' => $password, 'host' => $host);
     $em = EntityManager::create($connectionOptions, $config);
     Zend_Registry::set('**application_db_connection**', $em);
 }
Example #17
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;
 }
Example #18
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;
 }
Example #19
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);
 }
Example #20
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);
 }
Example #21
0
 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);
 }
Example #22
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);
 }
 /**
  * Create a mapping driver.
  *
  * @param Configuration $configuration
  * @return \Doctrine\Common\Persistence\Mapping\Driver\MappingDriver
  */
 protected function createOrmMappingDriver(Configuration $configuration)
 {
     $entityClasses = $this->getEntityClasses();
     $entityClasses[] = $this->getRepositoryObjectClass();
     $entityPaths = array_unique(array_map(function ($className) {
         $info = new \ReflectionClass($className);
         return dirname($info->getFileName());
     }, $entityClasses));
     return new StrictEntityDriverDecorator($configuration->newDefaultAnnotationDriver($entityPaths, false), $entityClasses);
 }
 /**
  * Return's the new driver instance.
  *
  * @param Doctrine\ORM\Configuration $configuration The DBAL configuration to create the driver for
  * @param array                      $paths         The path to the driver configuration
  * @param array                      $params        The additional configuration params
  *
  * @return Doctrine\Common\Persistence\Mapping\Driver\MappingDriver The driver instance
  */
 public static function get(Configuration $configuration, array $paths = array(), array $params = array())
 {
     // query whether or not we want to use the simple annotation reader
     $useSimpleAnnotationReader = false;
     if (isset($params[DriverKeys::USE_SIMPLE_ANNOTATION_READER])) {
         $useSimpleAnnotationReader = $params[DriverKeys::USE_SIMPLE_ANNOTATION_READER];
     }
     // create and return the driver instance
     return $configuration->newDefaultAnnotationDriver($paths, $useSimpleAnnotationReader);
 }
Example #25
0
 /**
  * Initialize metadata driver from resource options.
  *
  * @return void
  */
 protected function _initMetadataDriver()
 {
     $options = $this->getOptions();
     $mappingPaths = $options['metadata']['mappingPaths'];
     $driver = $options['metadata']['driver'];
     switch ($driver) {
         case 'yaml':
             $driver = new YamlDriver($mappingPaths);
             break;
         case 'xml':
             $driver = new XmlDriver($mappingPaths);
             break;
         case 'php':
             $driver = new PhpDriver($mappingPaths);
             break;
         default:
             $driver = $this->_config->newDefaultAnnotationDriver($mappingPaths);
     }
     $this->_config->setMetadataDriverImpl($driver);
 }
Example #26
0
 /**
  * Entidades::configuracion()
  * 
  * Genera el proceso de configuracion y preparacion
  * de los directorios de las entidades
  * 
  * @return object
  */
 private function configuracion()
 {
     $confg = new Configuration();
     $confg->setMetadataDriverImpl($confg->newDefaultAnnotationDriver($this->dirEntidades));
     $confg->setMetadataCacheImpl(new ArrayCache());
     $confg->setProxyDir($this->dirProxy);
     $confg->setProxyNamespace('Proxy');
     $confg->setAutoGenerateProxyClasses(true);
     $confg->setEntityNamespaces(array('Entidades\\' . $this->conexion . '\\' => $this->dirEntidades));
     $this->entityManager($confg);
 }
Example #27
0
 public function _getDefaultORMConfig()
 {
     $ormConfig = new ORM\Configuration();
     $pathToEntities = array(__DIR__ . '/Entities');
     $ORMDriver = $ormConfig->newDefaultAnnotationDriver($pathToEntities, false);
     $ormConfig->setMetadataDriverImpl($ORMDriver);
     // Do proxy stuff
     $ormConfig->setProxyDir(__DIR__ . '/Entities/Proxies');
     $ormConfig->setProxyNamespace('DrestTests\\Entities\\Proxies');
     $ormConfig->setAutoGenerateProxyClasses(true);
     return $ormConfig;
 }
 /**
  * @return EntityManager
  */
 protected function getMockEntityManager()
 {
     if (isset($this->mockEntityManager)) {
         return $this->mockEntityManager;
     }
     $config = new Configuration();
     $config->setMetadataCacheImpl(new ArrayCache());
     $config->setProxyDir(__DIR__ . '/Proxies');
     $config->setProxyNamespace('CrEOF\\Spatial\\Tests\\Proxies');
     $config->setMetadataDriverImpl($config->newDefaultAnnotationDriver(array(realpath(__DIR__ . '/Fixtures')), true));
     return EntityManager::create($this->getMockConnection(), $config);
 }
Example #29
0
 /**
  * @return \Doctrine\ORM\EntityManager
  */
 public function createEntityManager($conn, OrmConf $config = null, $eventManager = null)
 {
     if (empty($config)) {
         $config = new OrmConf();
         $config->setAutoCommit($this->autoCommit);
         $annotationDriver = $config->newDefaultAnnotationDriver($this->entitiesPaths);
         $config->setMetadataDriverImpl($annotationDriver);
         $config->setProxyDir($this->proxyDir);
         $config->setProxyNamespace($this->proxyNamespace);
     }
     return EntityManager::create($conn, $config, $eventManager);
 }
Example #30
0
 protected function setUp()
 {
     $configuration = new Configuration();
     $driverImpl = $configuration->newDefaultAnnotationDriver(__DIR__ . '/../../../../Model/Doctrine/ORM');
     $configuration->setMetadataDriverImpl($driverImpl);
     $configuration->setProxyDir(__DIR__ . '/../../Model/Doctrine/ORM/Proxy');
     $configuration->setProxyNamespace('Proxy');
     $configuration->setAutoGenerateProxyClasses(true);
     $this->entityManager = EntityManager::create(array('driver' => 'pdo_sqlite', 'path' => ':memory:'), $configuration);
     $schemaTool = new SchemaTool($this->entityManager);
     $schemaTool->createSchema($this->entityManager->getMetadataFactory()->getAllMetadata());
 }