/**
  * @param OrmConfiguration $configuration
  */
 public function addEntityNamespaces(OrmConfiguration $configuration)
 {
     $this->knownNamespaceAlias = array_merge($this->knownNamespaceAlias, $configuration->getEntityNamespaces());
     if ($configuration->getMetadataDriverImpl()) {
         $this->entityClassnames = array_merge($this->entityClassnames, $configuration->getMetadataDriverImpl()->getAllClassNames());
     }
 }
 /**
  * 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;
 }
 /**
  * getEntityManagerOptions
  *
  * Return the Doctrine ORM configuration instance 
  * 
  * @param array $options The options array
  * @return Doctrine\ORM\Configuration
  */
 protected function getConfiguration()
 {
     if (!isset($this->_config)) {
         $options = $this->getOptions();
         $config = new Configuration();
         $config->setProxyDir($options['proxydir']);
         if (APPLICATION_ENV == 'development') {
             $options['autogenerateproxies'] = true;
             $options['cache'] = 'array';
         }
         if (isset($options['cache'])) {
             $cache = $this->createCache($options['cache']);
             $config->setMetadataCacheImpl($cache);
             $config->setQueryCacheImpl($cache);
         }
         if (isset($options['proxynamespace'])) {
             $config->setProxyNamespace($options['proxynamespace']);
         }
         $config->setAutoGenerateProxyClasses(false);
         if (isset($options['autogenerateproxies']) && $options['autogenerateproxies']) {
             $config->setAutoGenerateProxyClasses(true);
         }
         $config->setMetadataDriverImpl($this->createMetadataDriver($options['metadatadriver'], $options['entitydir']));
         $this->_config = $config;
     }
     return $this->_config;
 }
Esempio n. 4
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);
 }
 /**
  * @return array
  */
 protected function prepareMocks()
 {
     $configuration = new Configuration();
     $configuration->addEntityNamespace('Stub', 'Oro\\Bundle\\BatchBundle\\Tests\\Unit\\ORM\\Query\\Stub');
     $classMetadata = new ClassMetadata('Entity');
     $classMetadata->mapField(['fieldName' => 'a', 'columnName' => 'a']);
     $classMetadata->mapField(['fieldName' => 'b', 'columnName' => 'b']);
     $classMetadata->setIdentifier(['a']);
     $platform = $this->getMockBuilder('Doctrine\\DBAL\\Platforms\\AbstractPlatform')->setMethods([])->disableOriginalConstructor()->getMockForAbstractClass();
     $statement = $this->getMockBuilder('Doctrine\\DBAL\\Statement')->setMethods(['fetch', 'fetchColumn', 'closeCursor'])->disableOriginalConstructor()->getMock();
     $driverConnection = $this->getMockBuilder('Doctrine\\DBAL\\Driver\\Connection')->setMethods(['query'])->disableOriginalConstructor()->getMockForAbstractClass();
     $driverConnection->expects($this->any())->method('query')->will($this->returnValue($statement));
     $driver = $this->getMockBuilder('Doctrine\\DBAL\\Driver')->setMethods(['connect', 'getDatabasePlatform'])->disableOriginalConstructor()->getMockForAbstractClass();
     $driver->expects($this->any())->method('connect')->will($this->returnValue($driverConnection));
     $driver->expects($this->any())->method('getDatabasePlatform')->will($this->returnValue($platform));
     $connection = $this->getMockBuilder('Doctrine\\DBAL\\Connection')->setMethods(['getDatabasePlatform', 'executeQuery'])->setConstructorArgs([[], $driver])->getMock();
     $connection->expects($this->any())->method('getDatabasePlatform')->will($this->returnValue($platform));
     /** @var UnitOfWork $unitOfWork */
     $unitOfWork = $this->getMockBuilder('UnitOfWork')->setMethods(['getEntityPersister'])->disableOriginalConstructor()->getMock();
     $entityManager = $this->getMockBuilder('Doctrine\\ORM\\EntityManager')->setMethods(['getConfiguration', 'getClassMetadata', 'getConnection', 'getUnitOfWork'])->disableOriginalConstructor()->getMock();
     $entityManager->expects($this->any())->method('getConfiguration')->will($this->returnValue($configuration));
     $entityManager->expects($this->any())->method('getClassMetadata')->will($this->returnValue($classMetadata));
     $entityManager->expects($this->any())->method('getConnection')->will($this->returnValue($connection));
     $entityManager->expects($this->any())->method('getUnitOfWork')->will($this->returnValue($unitOfWork));
     return [$entityManager, $connection, $statement];
 }
 /**
  * {@inheritDoc}
  */
 protected function setUp()
 {
     $this->configuration = $this->getMock('Doctrine\\ORM\\Configuration');
     $this->entityManager = $this->createEntityManager();
     $this->repositoryFactory = new DefaultRepositoryFactory();
     $this->configuration->expects($this->any())->method('getDefaultRepositoryClassName')->will($this->returnValue('Doctrine\\Tests\\Models\\DDC869\\DDC869PaymentRepository'));
 }
Esempio n. 7
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 . 'vendor/autoload.php';
     $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' => $db['default']['username'], 'password' => $db['default']['password'], 'host' => $db['default']['hostname'], 'dbname' => $db['default']['database']);
     // Create 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 __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);
 }
Esempio n. 10
0
 /**
  * {@inheritdoc}
  */
 public static function create($conn, Configuration $config, EventManager $eventManager = null)
 {
     if (!$config->getMetadataDriverImpl()) {
         throw ORMException::missingMappingDriverImpl();
     }
     switch (true) {
         case is_array($conn):
             if (!$eventManager) {
                 $eventManager = new EventManager();
             }
             if (isset($conn['prefix']) && $conn['prefix']) {
                 $eventManager->addEventListener(Events::loadClassMetadata, new TablePrefix($conn['prefix']));
             }
             $conn = \Doctrine\DBAL\DriverManager::getConnection($conn, $config, $eventManager);
             break;
         case $conn instanceof Connection:
             if ($eventManager !== null && $conn->getEventManager() !== $eventManager) {
                 throw ORMException::mismatchedEventManager();
             }
             break;
         default:
             throw new \InvalidArgumentException("Invalid argument: " . $conn);
     }
     return new self($conn, $config, $conn->getEventManager());
 }
Esempio n. 11
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);
 }
Esempio n. 12
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);
 }
 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");
     }
 }
Esempio n. 14
0
 /**
  * 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;
 }
 /**
  * Add driverChain and get orm config
  *
  * @return \Doctrine\ORM\Configuration
  */
 public function getConfiguration()
 {
     $driverChain = $this->getMetadataDriverImpl();
     // Inject the driverChain into the doctrine config
     $this->configuration->setMetadataDriverImpl($driverChain);
     return $this->configuration;
 }
Esempio n. 16
0
 /**
  * Get the Doctrine Configuration object
  *
  * @return \Doctrine\ORM\Configuration
  */
 public function getConfig()
 {
     if (null === $this->_config) {
         $this->_config = new \Doctrine\ORM\Configuration();
         $this->_config->setMetadataDriverImpl($this->getDriver());
     }
     return $this->_config;
 }
Esempio n. 17
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);
 }
Esempio n. 18
0
 protected function getEntityManager()
 {
     $config = new Configuration();
     $config->setProxyDir(sys_get_temp_dir() . '/JMSDoctrineTestProxies');
     $config->setProxyNamespace('JMS\\Tests\\Proxies');
     $config->setMetadataDriverImpl(new DoctrineDriver(new AnnotationReader(), __DIR__ . '/../../Fixtures/Doctrine'));
     $conn = array('driver' => 'pdo_sqlite', 'memory' => true);
     return EntityManager::create($conn, $config);
 }
 protected function setUp()
 {
     MockAnnotations::init($this);
     $this->em->expects($this->any())->method('getConfiguration')->will($this->returnValue($this->emConfiguration));
     $this->emConfiguration->expects($this->any())->method('getDefaultQueryHints')->will($this->returnValue([]));
     $this->searchQuery = $this->getMockForAbstractClass('\\Doctrine\\ORM\\AbstractQuery', array($this->em));
     $this->classMetadata->name = self::CLASS_NAME;
     $this->repository = new DoctrineTicketRepository($this->em, $this->classMetadata);
 }
Esempio n. 20
0
 public function setUp()
 {
     $configuration = new Configuration();
     $configuration->setResultCacheImpl(new \Doctrine\Common\Cache\ArrayCache());
     $configuration->setMetadataDriverImpl(new \Doctrine\ORM\Mapping\Driver\AnnotationDriver(new AnnotationReader(), realpath(__DIR__ . '/Models/')));
     $connection = \Doctrine\DBAL\DriverManager::getConnection(array('driver' => $GLOBALS['db_type'], 'host' => $GLOBALS['db_host'], 'dbname' => $GLOBALS['db_name'], 'user' => $GLOBALS['db_username'], 'password' => $GLOBALS['db_password']));
     $configuration->setMetadataCacheImpl(new \Doctrine\Common\Cache\ZendDataCache());
     $this->em = new \Lynx\EntityManager($connection, $configuration);
 }
 /**
  * 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);
 }
Esempio n. 22
0
 /**
  * @param Extension $extension
  */
 public function bootExtension(Extension $extension)
 {
     $extension->addSubscribers($this->evm, $this->em, $this->reader);
     if (is_array($extension->getFilters())) {
         foreach ($extension->getFilters() as $name => $filter) {
             $this->metadata->addFilter($name, $filter);
             $this->em->getFilters()->enable($name);
         }
     }
 }
Esempio n. 23
0
 /**
  * @param EntityManagerInterface $em
  * @param Configuration          $configuration
  */
 public function register(EntityManagerInterface $em, Configuration $configuration)
 {
     if ($this->debugbar->hasCollector('doctrine')) {
         $debugStack = $this->debugbar->getCollector('doctrine')->getDebugStack();
     } else {
         $debugStack = new DebugStack();
         $this->debugbar->addCollector(new DoctrineCollector($debugStack));
     }
     $configuration->setSQLLogger($debugStack);
 }
 /**
  * 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);
 }
Esempio n. 25
0
 private function createEntityManager(Connection $con)
 {
     $cfg = new Configuration();
     $cfg->setMetadataDriverImpl(new AnnotationDriver(new AnnotationReader(), array(__DIR__ . '/../../Fixtures/Doctrine/SingleTableInheritance')));
     $cfg->setAutoGenerateProxyClasses(true);
     $cfg->setProxyNamespace('JMS\\Serializer\\DoctrineProxy');
     $cfg->setProxyDir(sys_get_temp_dir() . '/serializer-test-proxies');
     $em = EntityManager::create($con, $cfg);
     return $em;
 }
Esempio n. 26
0
 public function register()
 {
     $this->container['object_manager'] = function () {
         $development = false;
         if (defined('ENVIRONMENT') && ENVIRONMENT === 'development') {
             $development = true;
         }
         $config = new Configuration();
         if ($development) {
             $cache = new ArrayCache();
         } else {
             $cache = new ApcCache();
         }
         $config->setMetadataCacheImpl($cache);
         $mappings = $this->container->get('config')['orm']['mappings'];
         $config->setMetadataDriverImpl(new XmlDriver($mappings));
         $proxyDir = $this->container->get('config')['orm']['proxy_dir'];
         $config->setProxyDir($proxyDir);
         $config->setQueryCacheImpl($cache);
         $config->setProxyNamespace('Jirro\\ORM\\Proxies');
         if ($development) {
             $config->setAutoGenerateProxyClasses(true);
         } else {
             $config->setAutoGenerateProxyClasses(false);
         }
         $dbConnection = $this->container->get('db_connection');
         $objectManager = ObjectManager::create($dbConnection, $config);
         return $objectManager;
     };
     $this->container->inflector('Jirro\\Component\\ORM\\ObjectManagerAwareInterface')->invokeMethod('setObjectManager', ['object_manager']);
 }
Esempio n. 27
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;
 }
Esempio n. 28
0
 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);
 }
Esempio n. 29
0
 public function __construct()
 {
     $this->setRoot("/var/www/html/uan/");
     $this->setEntidade(array($this->getRoot() . "models/"));
     $this->setIsDevMode(true);
     $mode = "DESENVOLVIMENTO";
     $config = Setup::createAnnotationMetadataConfiguration($this->getEntidade(), $this->getIsDevMode(), NULL, NULL, FALSE);
     if ($mode == "DESENVOLVIMENTO") {
         $cache = new \Doctrine\Common\Cache\ArrayCache();
     } else {
         $cache = new \Doctrine\Common\Cache\ApcCache();
     }
     $config = new Configuration();
     $config->setMetadataCacheImpl($cache);
     $driverImpl = $config->newDefaultAnnotationDriver($this->getRoot() . 'models/');
     $config->setMetadataDriverImpl($driverImpl);
     $config->setQueryCacheImpl($cache);
     $config->setProxyDir($this->getRoot() . 'proxies/');
     $config->setProxyNamespace('proxies');
     if ($mode == "DESENVOLVIMENTO") {
         $config->setAutoGenerateProxyClasses(true);
     } else {
         $config->setAutoGenerateProxyClasses(false);
     }
     $config = Setup::createAnnotationMetadataConfiguration($this->getEntidade(), $this->getIsDevMode(), NULL, NULL, FALSE);
     $dbParams = array('driver' => 'pdo_mysql', 'user' => 'root', 'password' => '', 'dbname' => 'ceafie', 'charset' => 'utf8', 'driverOptions' => array(1002 => 'SET NAMES utf8'));
     $this->em = EntityManager::create($dbParams, $config);
     $loader = new ClassLoader('Entity', __DIR__ . '/models');
     $loader->register();
 }
Esempio n. 30
0
 /**
  * @param array $settings
  * @param bool $debug
  * @return EntityManager
  * @throws \Doctrine\ORM\ORMException
  */
 public static function factory($settings, $debug = true)
 {
     if ($debug || !function_exists('apc_fetch')) {
         $cache = new ArrayCache();
     } else {
         $cache = new ApcCache();
     }
     $dbSettings = $settings['doctrine'];
     $config = new Configuration();
     $config->setMetadataCacheImpl($cache);
     // Do not use default Annotation driver
     $driverImpl = new AnnotationDriver(new AnnotationReader(), $dbSettings['entities']);
     // Allow all annotations
     AnnotationRegistry::registerLoader('class_exists');
     $config->setMetadataDriverImpl($driverImpl);
     $config->setQueryCacheImpl($cache);
     $config->setProxyDir($dbSettings['proxy_path']);
     $config->setProxyNamespace('Zaralab\\Doctrine\\Proxies');
     if ($debug) {
         $config->setAutoGenerateProxyClasses(true);
     } else {
         $config->setAutoGenerateProxyClasses(false);
     }
     $connectionOptions = $dbSettings['dbal'];
     return EntityManager::create($connectionOptions, $config);
 }