/** * 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; }
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); }
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); }
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 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() { $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(); }
/** * @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); }
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"); } }
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() { 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 __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); }
protected static function setUpEntityManager() { $config = new Configuration(); $config->setSQLLogger(null); $config->setAutoGenerateProxyClasses(true); $config->setProxyDir(\sys_get_temp_dir()); $config->setProxyNamespace('Proxies'); $config->setMetadataDriverImpl(static::getMetadataDriverImpl()); $config->setQueryCacheImpl(new ArrayCache()); $config->setMetadataCacheImpl(new ArrayCache()); $dbPath = __DIR__ . '/../db.sqlite'; if (file_exists($dbPath)) { unlink($dbPath); } $connection = ['driver' => 'pdo_sqlite', 'path' => $dbPath]; // Event listeners $interfaces = DoctrineBundleMapping::getDefaultImplementations(); $evm = new EventManager(); // Resolve entity target subscriber $rtel = new ResolveTargetEntityListener(); foreach ($interfaces as $model => $implementation) { $rtel->addResolveTargetEntity($model, $implementation, []); } $evm->addEventSubscriber($rtel); // Load metadata subscriber $lm = new LoadMetadataSubscriber([], $interfaces); $evm->addEventSubscriber($lm); static::$em = EntityManager::create($connection, $config, $evm); }
public function setUp() { if (!$this->entityManager) { EntityManagerContainer::clearEntityManager(); $configuration = new Configuration(); $configuration->setMetadataDriverImpl(new StaticPHPDriver(__DIR__.'/../../Model')); $configuration->setProxyDir(__DIR__.'/../../Proxy'); $configuration->setProxyNamespace('Proxy'); $configuration->setAutoGenerateProxyClasses(true); $this->entityManager = EntityManager::create(array( 'driver' => 'pdo_sqlite', 'path' => ':memory:', ), $configuration); // event manager $this->eventManager = $this->entityManager->getEventManager(); // metadata factory $this->metadataFactory = $this->entityManager->getMetadataFactory(); // create schema $schemaTool = new SchemaTool($this->entityManager); $schemaTool->createSchema($this->metadataFactory->getAllMetadata()); // entity manager container EntityManagerContainer::setEntityManager($this->entityManager); } }
/** * @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; }
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; }
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(); }
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); }
/** * Get entity manager. * * @return EntityManagerInterface */ protected function getEntityManager() { if (null === $this->entityManager) { $params = ['driver' => 'pdo_sqlite', 'memory' => true]; $cache = new ArrayCache(); /** @var AnnotationReader $reader */ $reader = new CachedReader(new AnnotationReader(), $cache); $annotationDriver = new AnnotationDriver($reader, [__DIR__ . '/../../../src/ORM']); $driverChain = new MappingDriverChain(); $driverChain->addDriver($annotationDriver, Commander::ENTITY_NAMESPACE); DoctrineExtensions::registerAbstractMappingIntoDriverChainORM($driverChain, $reader); $config = new Configuration(); $config->setAutoGenerateProxyClasses(true); $config->setProxyDir(sys_get_temp_dir()); $config->setProxyNamespace(Commander::ENTITY_NAMESPACE); $config->setMetadataDriverImpl($driverChain); $config->setMetadataCacheImpl($cache); $config->setQueryCacheImpl($cache); $config->setResultCacheImpl($cache); $config->setHydrationCacheImpl($cache); $timestampableListener = new TimestampableListener(); $timestampableListener->setAnnotationReader($annotationDriver->getReader()); $eventManager = new EventManager(); $eventManager->addEventSubscriber($timestampableListener); $entityManager = EntityManager::create($params, $config, $eventManager); $schemaTool = new SchemaTool($entityManager); $schemaTool->createSchema($entityManager->getMetadataFactory()->getAllMetadata()); $this->entityManager = $entityManager; } return $this->entityManager; }
/** * @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; }
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); }
/** * @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); }
public function testEnsureProductionSettingsAutoGenerateProxyClassesEval() { $this->setProductionSettings(); $this->configuration->setAutoGenerateProxyClasses(AbstractProxyFactory::AUTOGENERATE_EVAL); $this->setExpectedException('Doctrine\\ORM\\ORMException', 'Proxy Classes are always regenerating.'); $this->configuration->ensureProductionSettings(); }
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']); }); }
/** * 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(); }
public function createService(ServiceLocatorInterface $serviceLocator) { /** @var $options \DoctrineORMModule\Options\Configuration */ $options = $this->getOptions($serviceLocator); $config = new Configuration(); $config->setAutoGenerateProxyClasses($options->getGenerateProxies()); $config->setProxyDir($options->getProxyDir()); $config->setProxyNamespace($options->getProxyNamespace()); $config->setEntityNamespaces($options->getEntityNamespaces()); $config->setCustomDatetimeFunctions($options->getDatetimeFunctions()); $config->setCustomStringFunctions($options->getStringFunctions()); $config->setCustomNumericFunctions($options->getNumericFunctions()); $config->setClassMetadataFactoryName($options->getClassMetadataFactoryName()); foreach ($options->getNamedQueries() as $name => $query) { $config->addNamedQuery($name, $query); } foreach ($options->getNamedNativeQueries() as $name => $query) { $config->addNamedNativeQuery($name, $query['sql'], new $query['rsm']()); } foreach ($options->getCustomHydrationModes() as $modeName => $hydrator) { $config->addCustomHydrationMode($modeName, $hydrator); } foreach ($options->getFilters() as $name => $class) { $config->addFilter($name, $class); } $config->setMetadataCacheImpl($serviceLocator->get($options->getMetadataCache())); $config->setQueryCacheImpl($serviceLocator->get($options->getQueryCache())); $config->setResultCacheImpl($serviceLocator->get($options->getResultCache())); $config->setHydrationCacheImpl($serviceLocator->get($options->getHydrationCache())); $config->setMetadataDriverImpl($serviceLocator->get($options->getDriver())); if ($namingStrategy = $options->getNamingStrategy()) { if (is_string($namingStrategy)) { if (!$serviceLocator->has($namingStrategy)) { throw new InvalidArgumentException(sprintf('Naming strategy "%s" not found', $namingStrategy)); } $config->setNamingStrategy($serviceLocator->get($namingStrategy)); } else { $config->setNamingStrategy($namingStrategy); } } if ($repositoryFactory = $options->getRepositoryFactory()) { if (is_string($repositoryFactory)) { if (!$serviceLocator->has($repositoryFactory)) { throw new InvalidArgumentException(sprintf('Repository factory "%s" not found', $repositoryFactory)); } $config->setRepositoryFactory($serviceLocator->get($repositoryFactory)); } else { $config->setRepositoryFactory($repositoryFactory); } } if ($entityListenerResolver = $options->getEntityListenerResolver()) { if ($entityListenerResolver instanceof EntityListenerResolver) { $config->setEntityListenerResolver($entityListenerResolver); } else { $config->setEntityListenerResolver($serviceLocator->get($entityListenerResolver)); } } $this->setupDBALConfiguration($serviceLocator, $config); return $config; }
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); }
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); }
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() { //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); }