public function __construct()
 {
     require APPPATH . 'config/database.php';
     $dbParams = array('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' => array('charset' => $db['default']['char_set']));
     $isDevMode = true;
     $config = new Configuration();
     $setup = new Setup();
     $config = $setup->createAnnotationMetadataConfiguration(array(APPPATH . "models"), $isDevMode);
     $config = $setup->createYAMLMetadataConfiguration(array(APPPATH . "models/Yaml"), $isDevMode);
     $this->em = EntityManager::create($dbParams, $config);
 }
 public static function getConfig($appName, $modelNames = null)
 {
     $mappingDriver = new Tinebase_Record_DoctrineMappingDriver();
     if (!$modelNames) {
         $modelNames = array();
         foreach ($mappingDriver->getAllClassNames() as $modelName) {
             $modelConfig = $modelName::getConfiguration();
             if ($modelConfig->getApplName() == $appName) {
                 $modelNames[] = $modelName;
             }
         }
     }
     $tableNames = array();
     foreach ($modelNames as $modelName) {
         $modelConfig = $modelName::getConfiguration();
         if (!$mappingDriver->isTransient($modelName)) {
             throw new Setup_Exception('Model not yet doctrine2 ready');
         }
         $tableNames[] = SQL_TABLE_PREFIX . Tinebase_Helper::array_value('name', $modelConfig->getTable());
     }
     $config = Setup::createConfiguration();
     $config->setMetadataDriverImpl($mappingDriver);
     $config->setFilterSchemaAssetsExpression('/' . implode('|', $tableNames) . '/');
     return $config;
 }
 public function setUp()
 {
     $this->_oldEntityManager = \SoliantEntityAudit\Module::getModuleOptions()->getEntityManager();
     $this->_oldAuditedClassNames = \SoliantEntityAudit\Module::getModuleOptions()->getAuditedClassNames();
     $this->_oldJoinClasses = \SoliantEntityAudit\Module::getModuleOptions()->resetJoinClasses();
     $isDevMode = false;
     $config = Setup::createConfiguration($isDevMode, null, null);
     $chain = new DriverChain();
     // Use ZFC User for authentication tests
     $chain->addDriver(new XmlDriver(__DIR__ . '/../../../vendor/zf-commons/zfc-user-doctrine-orm/config/xml/zfcuser'), 'ZfcUser\\Entity');
     $chain->addDriver(new XmlDriver(__DIR__ . '/../../../vendor/zf-commons/zfc-user-doctrine-orm/config/xml/zfcuserdoctrineorm'), 'ZfcUserDoctrineORM\\Entity');
     $chain->addDriver(new StaticPHPDriver(__DIR__ . "/../Models"), 'SoliantEntityAuditTest\\Models\\LogRevision');
     $chain->addDriver(new AuditDriver('.'), 'SoliantEntityAudit\\Entity');
     $config->setMetadataDriverImpl($chain);
     // Replace entity manager
     $moduleOptions = \SoliantEntityAudit\Module::getModuleOptions();
     $conn = array('driver' => 'pdo_sqlite', 'memory' => true);
     $moduleOptions->setAuditedClassNames(array('SoliantEntityAuditTest\\Models\\LogRevision\\Album' => array(), 'SoliantEntityAuditTest\\Models\\LogRevision\\Performer' => array(), 'SoliantEntityAuditTest\\Models\\LogRevision\\Song' => array(), 'SoliantEntityAuditTest\\Models\\LogRevision\\SingleCoverArt' => array()));
     $entityManager = EntityManager::create($conn, $config);
     $moduleOptions->setEntityManager($entityManager);
     $schemaTool = new SchemaTool($entityManager);
     // Add auditing listener
     $entityManager->getEventManager()->addEventSubscriber(new LogRevision());
     $sql = $schemaTool->getUpdateSchemaSql($entityManager->getMetadataFactory()->getAllMetadata());
     #print_r($sql);die();
     $schemaTool->createSchema($entityManager->getMetadataFactory()->getAllMetadata());
     $this->_em = $entityManager;
 }
 public function __construct(Configuration $configuration)
 {
     $driver = new PHPDriver(__DIR__ . '/../Mapping/');
     $config = Setup::createConfiguration($configuration['debug']);
     $config->setMetadataDriverImpl($driver);
     $this->entityManager = EntityManager::create($configuration['database']['write_connection'], $config);
 }
예제 #5
0
 public function register(Application $app)
 {
     $app['orm.em.paths'] = $app->share(function () {
         return array();
     });
     $app['orm.event_manager'] = $app->share(function () use($app) {
         return new EventManager();
     });
     $app['orm.config'] = $app->share(function () use($app) {
         return Setup::createConfiguration($app['debug']);
     });
     $app['orm.anotation_reader'] = $app->share(function () use($app) {
         $annotationReader = new AnnotationReader();
         $cache = $app['orm.config']->getMetadataCacheImpl();
         return new CachedReader($annotationReader, $cache);
     });
     $app['orm.default_anotation_driver'] = $app->share(function () use($app) {
         AnnotationRegistry::registerFile($app['vendor_dir'] . '/doctrine/orm/lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php');
         return new AnnotationDriver($app['orm.anotation_reader'], $app['orm.em.paths']);
     });
     $app['orm.em'] = $app->share(function () use($app) {
         $annotationReader = $app['orm.anotation_reader'];
         $eventManager = $app['orm.event_manager'];
         $driverChain = new MappingDriverChain();
         $driverChain->setDefaultDriver($app['orm.default_anotation_driver']);
         DoctrineExtensions::registerMappingIntoDriverChainORM($driverChain, $annotationReader);
         $loggableListener = new LoggableListener();
         $loggableListener->setAnnotationReader($annotationReader);
         $loggableListener->setUsername('admin');
         $eventManager->addEventSubscriber($loggableListener);
         $config = $app['orm.config'];
         $config->setMetadataDriverImpl($driverChain);
         return EntityManager::create($app['db.default_options'], $config, $eventManager);
     });
 }
예제 #6
0
 public function register(Application $app)
 {
     $paths = array(realpath($app['config']['doctrine']['paths']['entity']));
     $isDevMode = $app['config']['doctrine']['devMode'];
     $config = Setup::createAnnotationMetadataConfiguration($paths, $isDevMode, null, null, false);
     $app['doctrine'] = EntityManager::create($app['config']['doctrine']['db'], $config);
 }
예제 #7
0
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     $config = $serviceLocator->get('config');
     // The parameters in Doctrine 2 and ZF2 are slightly different.
     // Below is an example how we can reuse the db settings
     $doctrineDbConfig = (array) $config['db'];
     $doctrineDbConfig['driver'] = strtolower($doctrineDbConfig['driver']);
     if (!isset($doctrineDbConfig['dbname'])) {
         $doctrineDbConfig['dbname'] = $doctrineDbConfig['database'];
     }
     if (!isset($doctrineDbConfig['host'])) {
         $doctrineDbConfig['host'] = $doctrineDbConfig['hostname'];
     }
     if (!isset($doctrineDbConfig['user'])) {
         $doctrineDbConfig['user'] = $doctrineDbConfig['username'];
     }
     $doctrineConfig = Setup::createAnnotationMetadataConfiguration($config['doctrine']['entity_path'], true);
     $entityManager = DoctrineEntityManager::create($doctrineDbConfig, $doctrineConfig);
     if (isset($config['doctrine']['initializers'])) {
         $eventManager = $entityManager->getEventManager();
         foreach ($config['doctrine']['initializers'] as $initializer) {
             $eventClass = new DoctrineEvent(new $initializer(), $serviceLocator);
             $eventManager->addEventListener(\Doctrine\ORM\Events::postLoad, $eventClass);
         }
     }
     if ($serviceLocator->has('doctrine-profiler')) {
         $profiler = $serviceLocator->get('doctrine-profiler');
         $entityManager->getConfiguration()->setSQLLogger($profiler);
     }
     return $entityManager;
 }
예제 #8
0
 /**
  * @return EntityManager
  */
 public function getEntityManager()
 {
     if (!$this->entityManager instanceof EntityManager) {
         $this->entityManager = EntityManager::create($this->getConfiguration()->get('database'), Setup::createAnnotationMetadataConfiguration([$this->rootPath . '/src/Classes/Entities/', __DIR__ . '/Domain/Entities/'], true));
     }
     return $this->entityManager;
 }
예제 #9
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $dbName = $input->getArgument('dbname');
     $path = $input->getOption('path');
     $extensionKey = $input->getOption('extension-key');
     $connectionParams = array('dbname' => $dbName, 'user' => $input->getOption('user'), 'password' => $input->getOption('password'), 'host' => $input->getOption('host'), 'driver' => $input->getOption('driver'), 'port' => $input->getOption('port'));
     $config = Setup::createAnnotationMetadataConfiguration(array('.'), false);
     $em = EntityManager::create($connectionParams, $config);
     $em->getConfiguration()->setMetadataDriverImpl(new \Doctrine\ORM\Mapping\Driver\DatabaseDriver($em->getConnection()->getSchemaManager()));
     $cmf = new DisconnectedClassMetadataFactory();
     $cmf->setEntityManager($em);
     if (is_null($extensionKey)) {
         $extensionKey = $dbName;
         if (self::DEFAULT_PATH != $path) {
             $extensionKey = array_pop(explode(DIRECTORY_SEPARATOR, $path));
         }
     }
     $exporter = new ExtbaseExporter($cmf);
     $exporter->setExtensionKey($extensionKey);
     $exporter->setPath($input->getOption('path'));
     self::mapDefaultInputOptions($exporter, $input);
     $output->writeln(sprintf('Exporting database schema "<info>%s</info>".', $dbName));
     $result = $exporter->exportJson();
     foreach ($exporter->getLogs() as $log) {
         $output->writeln($log);
     }
     return $result ? 0 : 1;
 }
예제 #10
0
파일: Mapper.php 프로젝트: uglybob/bh.net
 private function __construct()
 {
     $settings = Setup::getSettings();
     $config = \Doctrine\ORM\Tools\Setup::createXMLMetadataConfiguration([__DIR__ . '/../Mapper', 'Bh/Mapper'], $settings['DevMode']);
     $conn = array('driver' => 'pdo_mysql', 'user' => $settings['DbUser'], 'password' => $settings['DbPass'], 'dbname' => $settings['DbName']);
     self::$entityManager = \Doctrine\ORM\EntityManager::create($conn, $config);
 }
 public function __construct($sm, $params = array())
 {
     $this->sm = $sm;
     $path = $sm->get('pegase.core.path');
     foreach ($params['entities_folders'] as $i => $f) {
         $params['entities_folders'][$i] = $path->get_path($f);
     }
     $this->db_params = $params['database'];
     $isDevMode = true;
     $config = Setup::createAnnotationMetadataConfiguration($params['entities_folders'], $isDevMode);
     $this->em = EntityManager::create($params['database'], $config);
     /*
       // on vérifie la validité des mappings
     
       $validator = new SchemaValidator($this->em);
       $errors = $validator->validateMapping();
     
       if(count($errors) > 0) {
         // Lots of errors!
         echo implode("\n\n", $errors);
       }
       else
         echo "Les mappings sont ok.\n";
     */
     $this->schema = new Schema($sm, $this);
     $this->database = new Database($sm, $this);
     $this->entity = new Entity($sm, $this);
 }
예제 #12
0
 /**
  * This method is used to add an entity manager to the doctrine service.
  * @param $id string The id you would like to store with the entity manager.
  * @param ulfberht\module\doctrine\config $config The doctrine configuration for
  *        the entity manager.
  * @return void
  */
 public function addEntityManager($id, config $config)
 {
     $development = $config->develop ? true : false;
     $cache = $config->enableCache ? new ArrayCache() : null;
     //setup type of metadata reading
     switch ($config->type) {
         case 'annotation':
             $docConfig = Setup::createAnnotationMetadataConfiguration($config->paths, $development, null, $cache);
             break;
         case 'xml':
             $docConfig = Setup::createXMLMetadataConfiguration($config->paths, $development, null, $cache);
             break;
         case 'yaml':
             $docConfig = Setup::createYAMLMetadataConfiguration($config->paths, $development, null, $cache);
             break;
     }
     //setup caching
     if (!is_null($cache)) {
         $docConfig->setQueryCacheImpl($cache);
         $docConfig->setMetadataCacheImpl($cache);
     }
     //setup database connection
     $dbConnInfo = array('driver' => $config->database->driver, 'host' => $config->database->host, 'dbname' => $config->database->name, 'user' => $config->database->user, 'password' => $config->database->password);
     //store entity manager
     $this->_doctrineEntityMangers[$id] = EntityManager::create($dbConnInfo, $docConfig);
 }
예제 #13
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();
 }
예제 #14
0
 public function __construct()
 {
     $yamlParser = new Parser();
     $dbParams = $yamlParser->parse(file_get_contents(__DIR__ . '/parameters.yml'));
     $config = Setup::createAnnotationMetadataConfiguration(array(__DIR__ . '/../Entity'), true);
     $this->em = EntityManager::create($dbParams['database'], $config);
 }
예제 #15
0
 /**
  * @param array $database
  * @throws \Exception
  */
 public function __construct($database = [])
 {
     $this->db = $database;
     foreach ($this->db as $key => $db) {
         $this->allDb[$key] = function () use($db) {
             $db['dev'] = isset($db['dev']) && $db['dev'] ? true : false;
             if (isset($db['db_url'])) {
                 $dbParams = array('url' => $db['db_url']);
             } else {
                 if (!isset($db['driver']) || !isset($db['user']) || !isset($db['pass']) || !isset($db['host']) || !isset($db['db'])) {
                     throw new \Exception('Missing arguments for doctrine constructor');
                 }
                 $dbParams = array('driver' => $this->getDriver($db['driver']), 'user' => $db['user'], 'password' => $db['pass'], 'host' => $db['host'], 'dbname' => $db['db'], 'charset' => isset($db['charset']) ? $db['charset'] : 'utf8');
             }
             $evm = new EventManager();
             if (isset($db['prefix'])) {
                 $tablePrefix = new TablePrefix($db['prefix']);
                 $evm->addEventListener(Events::loadClassMetadata, $tablePrefix);
             }
             $config = Setup::createAnnotationMetadataConfiguration($db['path'], $db['dev']);
             if (!$db['dev']) {
                 $config->setQueryCacheImpl($db['cache']);
                 $config->setResultCacheImpl($db['cache']);
                 $config->setMetadataCacheImpl($db['cache']);
             }
             if (isset($db['functions']) && !empty($db['functions'])) {
                 $config->setCustomDatetimeFunctions($db['functions']['customDatetimeFunctions']);
                 $config->setCustomNumericFunctions($db['functions']['customNumericFunctions']);
                 $config->setCustomStringFunctions($db['functions']['customStringFunctions']);
             }
             return EntityManager::create($dbParams, $config, $evm);
         };
     }
 }
예제 #16
0
 protected function setUp()
 {
     $pathToEntities = [__DIR__ . '/Entity'];
     $isDevMode = true;
     $connectionParams = array('user' => 'user', 'password' => 'password', 'driver' => 'pdo_sqlite', 'memory' => true);
     $config = Setup::createConfiguration($isDevMode);
     $driver = new AnnotationDriver(new AnnotationReader(), $pathToEntities);
     AnnotationRegistry::registerLoader('class_exists');
     $config->setMetadataDriverImpl($driver);
     $this->em = EntityManager::create($connectionParams, $config);
     /*
      * Устанавливаем фикстуры, знаю что можно это сделать более универсально, но ... в данном контексте мне больше и не надо
      */
     $conn = $this->em->getConnection();
     $conn->exec("CREATE TABLE clients (id INTEGER PRIMARY KEY, name TEXT, surname TEXT);");
     $conn->exec("CREATE TABLE authors (id INTEGER PRIMARY KEY, name TEXT, surname TEXT);");
     $conn->exec("CREATE TABLE books (id INTEGER, owner_id INTEGER, name TEXT, surname TEXT, CONSTRAINT 'pk' PRIMARY KEY (id, owner_id));");
     $conn->exec("INSERT INTO clients (name,surname) VALUES('Nikita','Sapogov')");
     $conn->exec("INSERT INTO clients (name,surname) VALUES('Alex','Ivanov')");
     $conn->exec("INSERT INTO clients (name,surname) VALUES('Sura','Soir')");
     $conn->exec("INSERT INTO clients (name,surname) VALUES('Vasya','Poliakocv')");
     $conn->exec("INSERT INTO books (id, owner_id, name) VALUES (1,1,'SuperBookNAme')");
     $conn->exec("INSERT INTO books (id, owner_id, name) VALUES (2,15,'SuperBookNAme2')");
     $conn->exec("INSERT INTO books (id, owner_id, name) VALUES (3,3,'SuperBookNAme3')");
 }
예제 #17
0
 protected function setUp()
 {
     parent::setUp();
     $this->connection = DriverManager::getConnection(['driver' => 'pdo_sqlite', 'path' => self::SQLITE_PATH], new Configuration());
     $config = Setup::createAnnotationMetadataConfiguration([__DIR__ . '/../..'], true);
     $this->entityManager = EntityManager::create($this->connection, $config);
 }
예제 #18
0
 /**
  * Initializes the database (once).
  *
  * @throws \Doctrine\DBAL\DBALException
  * @throws \Doctrine\ORM\ORMException
  * @throws \Doctrine\ORM\Tools\ToolsException
  */
 protected function setUp()
 {
     if (null === static::$_conn) {
         $dbPath = __DIR__ . '/../../../db.sqlite';
         if (file_exists($dbPath)) {
             unlink($dbPath);
         }
         $params = ['driver' => 'pdo_sqlite', 'path' => $dbPath];
         static::$_conn = DriverManager::getConnection($params);
         static::$_conn->getConfiguration()->setSQLLogger(null);
     }
     if (null === static::$_em) {
         $paths = [__DIR__ . '/../../../../../src/Ekyna/Commerce/Bridge/Doctrine/ORM/Resources/mapping'];
         $isDevMode = true;
         $config = Setup::createXMLMetadataConfiguration($paths, $isDevMode);
         $em = EntityManager::create(static::$_conn, $config);
         $classes = [];
         foreach (static::$_classes as $class) {
             array_push($classes, $em->getClassMetadata($class));
         }
         $schemaTool = new SchemaTool($em);
         $schemaTool->dropSchema($classes);
         $schemaTool->createSchema($classes);
         // Load fixtures
         $loader = new Loader();
         $loader->loadFromDirectory(__DIR__ . '/../../../../../src/Ekyna/Commerce/Bridge/Doctrine/Fixtures');
         $purger = new ORMPurger();
         $executor = new ORMExecutor($em, $purger);
         $executor->execute($loader->getFixtures());
         static::$_em = $em;
     }
 }
예제 #19
0
 /**
  * @param ServiceLocatorInterface $serviceLocator
  * @return \Doctrine\ORM\EntityManager
  * @throws \Doctrine\ORM\ORMException
  */
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     $config = $serviceLocator->get('config');
     //set the Doctrine configuration array
     $doctrineDbSettings = (array) $config['db'];
     $doctrineDbSettings['driver'] = strtolower($config['db']['driver']);
     $doctrineDbSettings['dbname'] = isset($config['db']['database']) ? $config['db']['database'] : null;
     $doctrineDbSettings['host'] = isset($config['db']['hostname']) ? $config['db']['hostname'] : null;
     $doctrineDbSettings['user'] = isset($config['db']['username']) ? $config['db']['username'] : null;
     $proxyPath = isset($config['doctrine']['proxy_dir']) ? $config['doctrine']['proxy_dir'] : null;
     $isDevMode = isset($config['doctrine']['is_dev_mode']) ? $config['doctrine']['is_dev_mode'] : false;
     $doctrineConfig = Setup::createAnnotationMetadataConfiguration($config['doctrine']['entity_path'], $isDevMode, $proxyPath);
     $doctrineConfig->setAutoGenerateProxyClasses(true);
     $doctrineEntityManager = DocEManager::create($doctrineDbSettings, $doctrineConfig);
     if (isset($config['doctrine']['initializers'])) {
         $eventManager = $doctrineEntityManager->getEventManager();
         foreach ($config['doctrine']['initializers'] as $initializer) {
             $eventClass = new DoctrineEvent(new $initializer(), $serviceLocator);
             $eventManager->addEventListener(\Doctrine\ORM\Events::postLoad, $eventClass);
         }
     }
     if ($doctrineDbSettings['driver'] == 'pdo_sqlite') {
         //it is very important to make sure foreign keys are on with SQLite
         $query = $doctrineEntityManager->createNativeQuery("pragma foreign_keys=1", new \Doctrine\ORM\Query\ResultSetMapping());
         $query->execute();
     }
     return $doctrineEntityManager;
 }
 public function setUp()
 {
     // register our custom type
     if (!Type::hasType('hstore')) {
         Type::addType('hstore', 'EasyBib\\Doctrine\\Types\\Hstore');
     }
     $isDevMode = true;
     $doctrineConfig = Setup::createAnnotationMetadataConfiguration(array(__DIR__ . '/Entity'), $isDevMode);
     // database configuration parameters
     $rootTestsFolder = dirname(dirname(dirname(dirname(__DIR__))));
     $this->isTravis = getenv("TRAVIS");
     if (file_exists($rootTestsFolder . '/db-config.php')) {
         $dbConfig = (include $rootTestsFolder . '/db-config.php');
     } elseif (false !== $this->isTravis) {
         $dbConfig = (include $rootTestsFolder . '/db-config-travisci.php');
     } else {
         throw new \RuntimeException("No database configuration found.");
     }
     // create the entity manager
     $this->em = EntityManager::create($dbConfig, $doctrineConfig);
     // enable 'hstore'
     $this->em->getConnection()->exec("CREATE EXTENSION IF NOT EXISTS hstore");
     // register type with DBAL
     $this->em->getConnection()->getDatabasePlatform()->registerDoctrineTypeMapping('hstore', 'hstore');
     // make the PersistentObject happy
     PersistentObject::setObjectManager($this->em);
     // create table
     $this->setUpSchema($this->em);
 }
예제 #21
0
 public function __construct($configDir, $environment = 'dev')
 {
     if (!@file_exists("{$configDir}/config.yml")) {
         throw new \Exception("File: {$configDir}/config.yml does not exist.");
     }
     if (!@file_exists("{$configDir}/config_{$environment}.yml")) {
         throw new \Exception("File: {$configDir}/config_{$environment}.yml does not exist.");
     }
     try {
         $config = Yaml\Yaml::parse("{$configDir}/config.yml");
         $configEnv = Yaml\Yaml::parse("{$configDir}/config_{$environment}.yml");
     } catch (Yaml\Exception\ParseException $e) {
         throw new \Exception($e->getMessage());
     }
     $this->config = Arr::merge($config, $configEnv);
     $entityPaths = Arr::get($this->config, 'doctrine.entity.paths', array());
     $proxiesPath = Arr::get($this->config, 'doctrine.proxy.path', '');
     $proxiesNamespace = Arr::get($this->config, 'doctrine.proxy.namespace', '');
     $database = Arr::get($this->config, 'doctrine.database', array());
     $isDevMode = Arr::get($this->config, 'doctrine.isDevMode', TRUE);
     $this->cache = new \Doctrine\Common\Cache\ArrayCache();
     $this->reader = new AnnotationReader();
     $this->driver = new \Doctrine\ORM\Mapping\Driver\AnnotationDriver($this->reader, $entityPaths);
     $this->config = Setup::createAnnotationMetadataConfiguration($entityPaths, $isDevMode);
     $this->config->setMetadataCacheImpl($this->cache);
     $this->config->setQueryCacheImpl($this->cache);
     $this->config->setMetadataDriverImpl($this->driver);
     $this->config->setProxyDir($proxiesPath);
     $this->config->setProxyNamespace($proxiesNamespace);
     $this->config->setAutoGenerateProxyClasses($isDevMode);
     $this->entityManager = EntityManager::create($database, $this->config);
     $this->platform = $this->entityManager->getConnection()->getDatabasePlatform();
     $this->platform->registerDoctrineTypeMapping('enum', 'string');
 }
예제 #22
0
 protected function setUp()
 {
     $this->conn = $this->getSqliteConnection();
     $this->config = Setup::createXMLMetadataConfiguration(array(__DIR__ . '/_files'), true);
     $this->entityManager = EntityManager::create($this->conn, $this->config);
     $this->ormProvider = new OrmSchemaProvider($this->entityManager);
 }
예제 #23
0
 /**
  * @return EntityManager
  * @throws ServiceNotRegisteredException
  */
 public static function getEntityManager()
 {
     if (ServiceLocator::$entityManager === null) {
         ServiceLocator::$entityManager = EntityManager::create(['driver' => Config::DB_DRIVER, 'host' => Config::DB_HOST, 'dbname' => Config::DB_NAME, 'user' => Config::DB_USER, 'password' => Config::DB_PASS], Setup::createAnnotationMetadataConfiguration([__DIR__ . '/../Models'], Config::DEV_MODE, null, null, false));
     }
     return ServiceLocator::checkAndReturn(ServiceLocator::$entityManager);
 }
예제 #24
0
 public function hydrate(Jarvis $app)
 {
     $app['doctrine.cache'] = function () {
         return new VoidCache();
     };
     $app['doctrine.annotation.driver'] = function () {
         return new AnnotationDriver(new AnnotationReader());
     };
     $app['entyMgr'] = function (Jarvis $app) : EntityManagerInterface {
         $settings = $app['doctrine.settings'];
         $cache = $app['doctrine.cache'];
         $config = Setup::createConfiguration($settings['debug'], $settings['proxies_dir'], $cache);
         $driver = $app['doctrine.annotation.driver'];
         if (isset($settings['entities_paths'])) {
             $driver->addPaths((array) $settings['entities_paths']);
         }
         AnnotationRegistry::registerLoader('class_exists');
         $config->setMetadataDriverImpl($driver);
         $config->setAutoGenerateProxyClasses($settings['debug']);
         $config->setMetadataCacheImpl($cache);
         $config->setResultCacheImpl($cache);
         $config->setQueryCacheImpl($cache);
         $entyMgr = EntityManager::create($settings['dbal'], $config);
         if (isset($app['doctrine.orm.entyMgr.decorator']) && is_string($fqcn = $app['doctrine.orm.entyMgr.decorator']) && is_subclass_of($fqcn, EntityManagerDecorator::class)) {
             $entyMgr = new $fqcn($entyMgr);
         }
         $entyMgr->getEventManager()->addEventListener([Events::preRemove, Events::postRemove, Events::prePersist, Events::postPersist, Events::preUpdate, Events::postUpdate, Events::postLoad, Events::preFlush, Events::onFlush, Events::postFlush, Events::onClear], new EventListener($app));
         $app->broadcast(DoctrineReadyEvent::READY_EVENT, new DoctrineReadyEvent($entyMgr));
         return $entyMgr;
     };
     $app['db_conn'] = function ($app) {
         $app['entyMgr']->getConnection();
     };
     $app->lock(['entyMgr', 'db_conn', 'doctrine.annotation.driver']);
 }
 /**
  * Just for internal use, could be overridden in child classes
  * User $em property in case if you need EntityManager
  *
  * @return EntityManagerMock
  */
 protected function getEntityManagerInstanceMock()
 {
     $this->config = Setup::createAnnotationMetadataConfiguration(array('./Fixtures'), true);
     $this->config->setQuoteStrategy(new QuotingStrategy());
     $conn = array('driverClass' => 'Luxifer\\Tests\\Mocks\\DriverMock', 'wrapperClass' => 'Luxifer\\Tests\\Mocks\\ConnectionMock', 'user' => 'john', 'password' => 'wayne');
     $conn = DriverManager::getConnection($conn, $this->config);
     $this->config->setProxyDir(__DIR__ . '/Proxies');
     $this->config->setProxyNamespace('Luxifer\\Tests\\Proxies');
     $this->config->addCustomDatetimeFunction('date', 'Luxifer\\DQL\\Datetime\\Date');
     $this->config->addCustomDatetimeFunction('datediff', 'Luxifer\\DQL\\Datetime\\DateDiff');
     $this->config->addCustomDatetimeFunction('day', 'Luxifer\\DQL\\Datetime\\Day');
     $this->config->addCustomDatetimeFunction('dayofmonth', 'Luxifer\\DQL\\Datetime\\DayOfMonth');
     $this->config->addCustomDatetimeFunction('week', 'Luxifer\\DQL\\Datetime\\Week');
     $this->config->addCustomDatetimeFunction('dayofweek', 'Luxifer\\DQL\\Datetime\\DayOfWeek');
     $this->config->addCustomDatetimeFunction('dayofyear', 'Luxifer\\DQL\\Datetime\\DayOfYear');
     $this->config->addCustomDatetimeFunction('hour', 'Luxifer\\DQL\\Datetime\\Hour');
     $this->config->addCustomDatetimeFunction('minute', 'Luxifer\\DQL\\Datetime\\Minute');
     $this->config->addCustomDatetimeFunction('month', 'Luxifer\\DQL\\Datetime\\Month');
     $this->config->addCustomDatetimeFunction('quarter', 'Luxifer\\DQL\\Datetime\\Quarter');
     $this->config->addCustomDatetimeFunction('second', 'Luxifer\\DQL\\Datetime\\Second');
     $this->config->addCustomDatetimeFunction('time', 'Luxifer\\DQL\\Datetime\\Time');
     $this->config->addCustomDatetimeFunction('year', 'Luxifer\\DQL\\Datetime\\Year');
     $this->config->addCustomDatetimeFunction('convert_tz', 'Luxifer\\DQL\\Datetime\\ConvertTZ');
     $this->config->addCustomDatetimeFunction('date_format', 'Luxifer\\DQL\\Datetime\\DateFormat');
     $this->config->addCustomDatetimeFunction('concat_ws', 'Luxifer\\DQL\\String\\ConcatWs');
     return EntityManagerMock::create($conn, $this->config);
 }
예제 #26
0
 public function register(Application $app)
 {
     $dbConnection = array('driver' => 'pdo_mysql', 'host' => 'localhost', 'user' => 'root', 'password' => 'password', 'dbname' => 'icfs');
     $config = \Doctrine\ORM\Tools\Setup::createAnnotationMetadataConfiguration(array(__DIR__ . "/Model"), true);
     $app['db.em'] = \Doctrine\ORM\EntityManager::create($dbConnection, $config);
     $app->register(new \Silex\Provider\DoctrineServiceProvider(), array('db.options' => $dbConnection));
 }
예제 #27
0
 public function __construct()
 {
     try {
         $conn = array("driver" => "pdo_mysql", "host" => "localhost", "port" => "3306", "user" => "root", "password" => "", "dbname" => "controle_gastos");
         /*
         var_dump(__DIR__);
         var_dump(PP);
         exit;
         */
         $loader = new \Doctrine\Common\ClassLoader("Entities", __DIR__);
         $loader->register();
         $config = Setup::createAnnotationMetadataConfiguration(array("../../" . __DIR__ . "/app/models"), false);
         $em = EntityManager::create($conn, $config);
         $cmf = new DisconnectedClassMetadataFactory();
         $cmf->setEntityManager($em);
         $em->getConnection()->getDatabasePlatform()->registerDoctrineTypeMapping('set', 'string');
         $em->getConnection()->getDatabasePlatform()->registerDoctrineTypeMapping('enum', 'string');
         $driver = new DatabaseDriver($em->getConnection()->getSchemaManager());
         $em->getConfiguration()->setMetadataDriverImpl($driver);
         $metadata = $cmf->getAllMetadata();
         $generator = new EntityGenerator();
         $generator->setGenerateAnnotations(true);
         $generator->setGenerateStubMethods(true);
         $generator->setRegenerateEntityIfExists(true);
         $generator->setUpdateEntityIfExists(true);
         $generator->generate($metadata, "../../" . __DIR__ . "/app/models");
     } catch (\Exception $e) {
         throw $e;
     }
 }
예제 #28
0
 public function __construct($setConfigFiles = true)
 {
     if ($setConfigFiles) {
         $this->configFile = __DIR__ . '/../../../config.php';
         $this->localConfigFile = __DIR__ . '/../../../config.local.php';
     }
     parent::__construct();
     $isDevMode = false;
     $cache = new \Doctrine\Common\Cache\FilesystemCache(__DIR__ . '/../../tmp');
     $config = Setup::createConfiguration($isDevMode, __DIR__ . '/../../tmp', $cache);
     $config->setProxyDir(__DIR__ . '/../../tmp');
     $config->setProxyNamespace('MyProject\\Proxies');
     $config->setAutoGenerateProxyClasses(true);
     $paths = [__DIR__ . '/../Entity'];
     $driver = new \Doctrine\ORM\Mapping\Driver\AnnotationDriver(new AnnotationReader(), $paths);
     \Doctrine\Common\Annotations\AnnotationRegistry::registerLoader('class_exists');
     $config->setMetadataDriverImpl($driver);
     //$config->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger());
     $conn = ['driver' => 'mysqli', 'host' => '127.0.0.1', 'user' => $this->databaseFactory->getUserName(), 'password' => $this->databaseFactory->getPassword(), 'dbname' => $this->databaseFactory->getDatabaseName()];
     $this->entityManager = EntityManager::create($conn, $config);
     $this->entityManager->getConnection()->getDatabasePlatform()->registerDoctrineTypeMapping('enum', 'string');
     \Doctrine\DBAL\Types\Type::addType('enum', StringType::class);
     $this->entityManager->getConfiguration()->addCustomStringFunction('DATE', DateFunction::class);
     $this->user = $this->entityManager->createQueryBuilder()->select('u')->from(Sources\Tests\Entity\User::class, 'u');
 }
예제 #29
0
 private function initDB()
 {
     require_once APPPATH . 'config/database.php';
     // Database connection information
     $dbParams = array('driver' => 'pdo_mysql', 'user' => "helpie38_neo", 'password' => "x#rnoPA;P}74", 'host' => "localhost", 'dbname' => "helpie38_main");
     $path = array(APPPATH . 'BusinessLogic/Models/Entities');
     $config = Doctrine\ORM\Tools\Setup::createAnnotationMetadataConfiguration($path, true);
     $config->addEntityNamespace("Entities", 'BusinessLogic\\Models\\Entities');
     // $config->setResultCacheImpl(new \Doctrine\Common\Cache\ApcCache());
     // $config->setQueryCacheImpl(new \Doctrine\Common\Cache\ApcCache());
     // $config->setMetadataCacheImpl(new \Doctrine\Common\Cache\ApcCache());
     //$config->setProxyDir("NeoMvc/Proxy");
     //$config->setProxyNamespace("Proxy");
     // $config->setResultCacheImpl(new \Doctrine\Common\Cache\ArrayCache());
     // $config->setQueryCacheImpl(new \Doctrine\Common\Cache\ArrayCache());
     // $config->setMetadataCacheImpl(new \Doctrine\Common\Cache\ArrayCache());
     require_once APPPATH . "libraries/UVd/DoctrineFunction/DateFormat.php";
     $config->addCustomStringFunction("DATE_FORMAT", "\\UVd\\DoctrineFunction\\DateFormat");
     $config->setAutoGenerateProxyClasses(true);
     $em = EntityManager::create($dbParams, $config);
     try {
         // $this->updateSchema($em);
     } catch (\Exception $e) {
         echo $e->getMessage();
     }
     return $em;
 }
 public function buildProdConfig()
 {
     $proxies = dirname(__FILE__) . DS . 'proxies';
     $config = Setup::createXMLMetadataConfiguration($this->paths, false, $proxies);
     $config->setProxyNamespace('Infrastructure\\Persistence\\Doctrine\\Proxies');
     return $config;
 }