Beispiel #1
0
 public function testConfigureFilter()
 {
     $config = new \Doctrine\ORM\Configuration();
     $config->addFilter("locale", "\\Doctrine\\Tests\\ORM\\Functional\\MyLocaleFilter");
     $this->assertEquals("\\Doctrine\\Tests\\ORM\\Functional\\MyLocaleFilter", $config->getFilterClassName("locale"));
     $this->assertNull($config->getFilterClassName("foo"));
 }
Beispiel #2
0
 protected static function getEntityManager($options)
 {
     $config = new \Doctrine\ORM\Configuration();
     // Handling for class names specified as platform types.
     if ($options['conn']['platform']) {
         $class_obj = new \ReflectionClass($options['conn']['platform']);
         $options['conn']['platform'] = $class_obj->newInstance();
     }
     // Special handling for the utf8mb4 type.
     if ($options['conn']['driver'] == 'pdo_mysql' && $options['conn']['charset'] == 'utf8mb4') {
         $options['conn']['platform'] = new \DF\Doctrine\Platform\MysqlUnicode();
     }
     $metadata_driver = $config->newDefaultAnnotationDriver($options['modelPath']);
     $config->setMetadataDriverImpl($metadata_driver);
     $cache = new \DF\Doctrine\Cache();
     // $cache->setNamespace('doctrine_');
     $config->setMetadataCacheImpl($cache);
     $config->setQueryCacheImpl($cache);
     $config->setResultCacheImpl($cache);
     $config->setProxyDir($options['proxyPath']);
     $config->setProxyNamespace($options['proxyNamespace']);
     if (isset($options['conn']['debug']) && $options['conn']['debug']) {
         $config->setSQLLogger(new \DF\Doctrine\Logger\EchoSQL());
     }
     $config->addFilter('softdelete', '\\DF\\Doctrine\\Filter\\SoftDelete');
     $config->addCustomNumericFunction('RAND', '\\DF\\Doctrine\\Functions\\Rand');
     $evm = new \Doctrine\Common\EventManager();
     $em = \Doctrine\ORM\EntityManager::create($options['conn'], $config, $evm);
     $em->getFilters()->enable("softdelete");
     // Try the connection before rendering the page.
     $em->getConnection()->connect();
     return $em;
 }
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     /** @var $options \DoctrineORMModule\Options\Configuration */
     $options = $this->getOptions($serviceLocator);
     $config = new \Doctrine\ORM\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());
     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->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);
         }
     }
     $this->setupDBALConfiguration($serviceLocator, $config);
     return $config;
 }
 /**
  * Gets the 'doctrine.orm.default_entity_manager' service.
  *
  * This service is shared.
  * This method always returns the same instance of the service.
  *
  * @param bool    $lazyLoad whether to try lazy-loading the service with a proxy
  *
  * @return \Doctrine\ORM\EntityManager A Doctrine\ORM\EntityManager instance
  */
 protected function getDoctrine_Orm_DefaultEntityManagerService($lazyLoad = true)
 {
     $a = $this->get('annotation_reader');
     $b = new \Doctrine\ORM\Mapping\Driver\AnnotationDriver($a, array(0 => $this->targetDirs[3] . '/vendor/gedmo/doctrine-extensions/lib/Gedmo/Translatable/Entity', 1 => $this->targetDirs[3] . '/vendor/gedmo/doctrine-extensions/lib/Gedmo/Translator/Entity', 2 => $this->targetDirs[3] . '/vendor/gedmo/doctrine-extensions/lib/Gedmo/Loggable/Entity', 3 => $this->targetDirs[3] . '/vendor/gedmo/doctrine-extensions/lib/Gedmo/Tree/Entity', 4 => $this->targetDirs[3] . '/vendor/7rin0/bigfoot-core-bundle/Bigfoot/Bundle/CoreBundle/Entity', 5 => $this->targetDirs[3] . '/vendor/7rin0/bigfoot-context-bundle/Bigfoot/Bundle/ContextBundle/Entity', 6 => $this->targetDirs[3] . '/vendor/7rin0/bigfoot-navigation-bundle/Bigfoot/Bundle/NavigationBundle/Entity', 7 => $this->targetDirs[3] . '/vendor/7rin0/bigfoot-user-bundle/Bigfoot/Bundle/UserBundle/Entity', 8 => $this->targetDirs[3] . '/vendor/7rin0/bigfoot-content-bundle/Bigfoot/Bundle/ContentBundle/Entity', 9 => $this->targetDirs[3] . '/vendor/7rin0/bigfoot-media-bundle/Bigfoot/Bundle/MediaBundle/Entity'));
     $c = new \Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain();
     $c->addDriver($b, 'Gedmo\\Translatable\\Entity');
     $c->addDriver($b, 'Gedmo\\Translator\\Entity');
     $c->addDriver($b, 'Gedmo\\Loggable\\Entity');
     $c->addDriver($b, 'Gedmo\\Tree\\Entity');
     $c->addDriver($b, 'Bigfoot\\Bundle\\CoreBundle\\Entity');
     $c->addDriver($b, 'Bigfoot\\Bundle\\ContextBundle\\Entity');
     $c->addDriver($b, 'Bigfoot\\Bundle\\NavigationBundle\\Entity');
     $c->addDriver($b, 'Bigfoot\\Bundle\\UserBundle\\Entity');
     $c->addDriver($b, 'Bigfoot\\Bundle\\ContentBundle\\Entity');
     $c->addDriver($b, 'Bigfoot\\Bundle\\MediaBundle\\Entity');
     $d = new \Doctrine\ORM\Configuration();
     $d->setEntityNamespaces(array('GedmoTranslatable' => 'Gedmo\\Translatable\\Entity', 'GedmoTranslator' => 'Gedmo\\Translator\\Entity', 'GedmoLoggable' => 'Gedmo\\Loggable\\Entity', 'GedmoTree' => 'Gedmo\\Tree\\Entity', 'BigfootCoreBundle' => 'Bigfoot\\Bundle\\CoreBundle\\Entity', 'BigfootContextBundle' => 'Bigfoot\\Bundle\\ContextBundle\\Entity', 'BigfootNavigationBundle' => 'Bigfoot\\Bundle\\NavigationBundle\\Entity', 'BigfootUserBundle' => 'Bigfoot\\Bundle\\UserBundle\\Entity', 'BigfootContentBundle' => 'Bigfoot\\Bundle\\ContentBundle\\Entity', 'BigfootMediaBundle' => 'Bigfoot\\Bundle\\MediaBundle\\Entity'));
     $d->setMetadataCacheImpl($this->get('doctrine_cache.providers.doctrine.orm.default_metadata_cache'));
     $d->setQueryCacheImpl($this->get('doctrine_cache.providers.doctrine.orm.default_query_cache'));
     $d->setResultCacheImpl($this->get('doctrine_cache.providers.doctrine.orm.default_result_cache'));
     $d->setMetadataDriverImpl($c);
     $d->setProxyDir(__DIR__ . '/doctrine/orm/Proxies');
     $d->setProxyNamespace('Proxies');
     $d->setAutoGenerateProxyClasses(true);
     $d->setClassMetadataFactoryName('Doctrine\\ORM\\Mapping\\ClassMetadataFactory');
     $d->setDefaultRepositoryClassName('Doctrine\\ORM\\EntityRepository');
     $d->setNamingStrategy(new \Doctrine\ORM\Mapping\UnderscoreNamingStrategy());
     $d->setQuoteStrategy(new \Doctrine\ORM\Mapping\DefaultQuoteStrategy());
     $d->setEntityListenerResolver($this->get('doctrine.orm.default_entity_listener_resolver'));
     $d->addCustomStringFunction('regexp', 'Bigfoot\\Bundle\\CoreBundle\\ORM\\Doctrine\\Query\\MySQL\\Regexp');
     $d->addCustomStringFunction('substring_index', 'Bigfoot\\Bundle\\CoreBundle\\ORM\\Doctrine\\Query\\MySQL\\SubstringIndex');
     $d->addCustomStringFunction('greatest', 'Bigfoot\\Bundle\\CoreBundle\\ORM\\Doctrine\\Query\\MySQL\\Greatest');
     $d->addCustomNumericFunction('acos', 'Bigfoot\\Bundle\\CoreBundle\\ORM\\Acos');
     $d->addCustomNumericFunction('cos', 'Bigfoot\\Bundle\\CoreBundle\\ORM\\Cos');
     $d->addCustomNumericFunction('sin', 'Bigfoot\\Bundle\\CoreBundle\\ORM\\Sin');
     $d->addCustomNumericFunction('radians', 'Bigfoot\\Bundle\\CoreBundle\\ORM\\Radians');
     $d->addCustomNumericFunction('GEO_DISTANCE', 'Craue\\GeoBundle\\Doctrine\\Query\\Mysql\\GeoDistance');
     $d->addCustomNumericFunction('GEO_DISTANCE_BY_POSTAL_CODE', 'Craue\\GeoBundle\\Doctrine\\Query\\Mysql\\GeoDistanceByPostalCode');
     $d->addFilter('softdeleteable', 'Gedmo\\SoftDeleteable\\Filter\\SoftDeleteableFilter');
     $this->services['doctrine.orm.default_entity_manager'] = $instance = \Doctrine\ORM\EntityManager::create($this->get('doctrine.dbal.default_connection'), $d);
     $this->get('doctrine.orm.default_manager_configurator')->configure($instance);
     return $instance;
 }
 /**
  * Get the Doctrine EntityManager
  *
  * @return \Doctrine\ORM\EntityManager
  */
 public function getEntityManager()
 {
     if ($this->entityManager !== null) {
         return $this->entityManager;
     }
     Tx_Doctrine2_ExtbaseBootstrap::bootstrapAutoloading();
     // Dev Mode decides if proxies are auto-generated every request
     // and what kind of cache is used for the metadata.
     $isDevMode = self::getDevMode();
     $config = new \Doctrine\ORM\Configuration();
     if ($isDevMode) {
         $config->setAutoGenerateProxyClasses(true);
     }
     $config->setProxyDir(PATH_site . 'typo3temp/doctrine2');
     $config->setProxyNamespace('TxDoctrine2Proxies');
     $cache = $this->createCache($isDevMode);
     $config->setMetadataCacheImpl($cache);
     $config->setQueryCacheImpl($cache);
     $paths = $this->getEntityDirectories();
     $driverImpl = $config->newDefaultAnnotationDriver($paths);
     $config->setMetadataDriverImpl($driverImpl);
     $config->addFilter('enableFields', 'Tx_Doctrine2_Persistence_EnableFieldsFilter');
     if (!\Doctrine\DBAL\Types\Type::hasType('timestamp')) {
         \Doctrine\DBAL\Types\Type::addType('timestamp', 'Tx_Doctrine2_Types_TimestampType');
     }
     $dbParams = $this->getDatabaseParams();
     $evm = $this->createEventManager();
     $this->entityManager = \Doctrine\ORM\EntityManager::create($dbParams, $config, $evm);
     $this->entityManager->getFilters('enableFields')->enable('enableFields');
     if ($this->objectManager instanceof Tx_Doctrine2_ObjectManager) {
         $this->objectManager->setEntityManager($this->entityManager);
     }
     return $this->entityManager;
 }
Beispiel #6
0
 /**
  * @expectedException InvalidArgumentException
  */
 public function testConfigureFilterFails()
 {
     $config = new \Doctrine\ORM\Configuration();
     $invalidFilter = $this->getMock('\\StdClass');
     $config->addFilter("geolocation", $invalidFilter);
 }