/** * @return Doctrine\Common\Annotations\AnnotationReader */ public function createServiceAnnotations__reflectionReader() { $service = new Doctrine\Common\Annotations\AnnotationReader(); $service->addGlobalIgnoredName('persistent'); $service->addGlobalIgnoredName('serializationVersion'); return $service; }
public function createDocumentManager(array $paths = null) { $reader = new \Doctrine\Common\Annotations\AnnotationReader(); $reader->addGlobalIgnoredName('group'); if (empty($paths)) { $paths = array(__DIR__ . "/../../Models"); } $metaDriver = new AnnotationDriver($reader, $paths); $factoryclass = isset($GLOBALS['DOCTRINE_PHPCR_FACTORY']) ? $GLOBALS['DOCTRINE_PHPCR_FACTORY'] : '\\Jackalope\\RepositoryFactoryJackrabbit'; if ($factoryclass === '\\Jackalope\\RepositoryFactoryDoctrineDBAL') { $params = array(); foreach ($GLOBALS as $key => $value) { if (0 === strpos($key, 'jackalope.doctrine.dbal.')) { $params[substr($key, strlen('jackalope.doctrine.dbal.'))] = $value; } } if (isset($params['username'])) { $params['user'] = $params['username']; } $GLOBALS['jackalope.doctrine_dbal_connection'] = \Doctrine\DBAL\DriverManager::getConnection($params); } $parameters = array_intersect_key($GLOBALS, $factoryclass::getConfigurationKeys()); // factory will return null if it gets unknown parameters $repository = $factoryclass::getRepository($parameters); $this->assertNotNull($repository, 'There is an issue with your parameters: ' . var_export(array_keys($parameters), true)); $workspace = isset($GLOBALS['DOCTRINE_PHPCR_WORKSPACE']) ? $GLOBALS['DOCTRINE_PHPCR_WORKSPACE'] : 'tests'; $user = isset($GLOBALS['DOCTRINE_PHPCR_USER']) ? $GLOBALS['DOCTRINE_PHPCR_USER'] : ''; $pass = isset($GLOBALS['DOCTRINE_PHPCR_PASS']) ? $GLOBALS['DOCTRINE_PHPCR_PASS'] : ''; $credentials = new \PHPCR\SimpleCredentials($user, $pass); $session = $repository->login($credentials, $workspace); $this->sessions[] = $session; $config = new \Doctrine\ODM\PHPCR\Configuration(); $config->setMetadataDriverImpl($metaDriver); return DocumentManager::create($session, $config); }
/** * @return $this */ public function connect() { // Prevent to connect twice if ($this->entityManager) { return $this; } $applicationDir = $this->core->getApplicationDir(); $this->createModuleDirCache(); $cache = $this->cache->getCacheProvider(); $config = new \Doctrine\ORM\Configuration(); $config->setMetadataCacheImpl($cache); $config->addCustomStringFunction('MD5', '\\DoctrineExtensions\\Query\\Mysql\\Md5'); $config->addCustomStringFunction('ACOS', '\\DoctrineExtensions\\Query\\Mysql\\Acos'); $config->addCustomStringFunction('ASIN', '\\DoctrineExtensions\\Query\\Mysql\\Asin'); $config->addCustomStringFunction('ATAN', '\\DoctrineExtensions\\Query\\Mysql\\Atan'); $config->addCustomStringFunction('ATAN2', '\\DoctrineExtensions\\Query\\Mysql\\Atan2'); $config->addCustomStringFunction('BINARY', '\\DoctrineExtensions\\Query\\Mysql\\Binary'); $config->addCustomStringFunction('CHARLENGTH', '\\DoctrineExtensions\\Query\\Mysql\\CharLength'); $config->addCustomStringFunction('CONCATWS', '\\DoctrineExtensions\\Query\\Mysql\\ConcatWs'); $config->addCustomStringFunction('COS', '\\DoctrineExtensions\\Query\\Mysql\\Cos'); $config->addCustomStringFunction('COT', '\\DoctrineExtensions\\Query\\Mysql\\COT'); $config->addCustomStringFunction('COUNTIF', '\\DoctrineExtensions\\Query\\Mysql\\CountIf'); $config->addCustomStringFunction('CRC32', '\\DoctrineExtensions\\Query\\Mysql\\Crc32'); $config->addCustomStringFunction('DATE', '\\DoctrineExtensions\\Query\\Mysql\\Date'); $config->addCustomStringFunction('DATEADD', '\\DoctrineExtensions\\Query\\Mysql\\DateAdd'); $config->addCustomStringFunction('DATEDIFF', '\\DoctrineExtensions\\Query\\Mysql\\DateFormat'); $config->addCustomStringFunction('DAY', '\\DoctrineExtensions\\Query\\Mysql\\Day'); $config->addCustomStringFunction('DEGREES', '\\DoctrineExtensions\\Query\\Mysql\\Degrees'); $config->addCustomStringFunction('FIELD', '\\DoctrineExtensions\\Query\\Mysql\\Field'); $config->addCustomStringFunction('FINDINSET', '\\DoctrineExtensions\\Query\\Mysql\\FindInSet'); $config->addCustomStringFunction('GROUPCONCAT', '\\DoctrineExtensions\\Query\\Mysql\\GroupConcat'); $config->addCustomStringFunction('HOUR', '\\DoctrineExtensions\\Query\\Mysql\\Hour'); $config->addCustomStringFunction('IFELSE', '\\DoctrineExtensions\\Query\\Mysql\\IfElse'); $config->addCustomStringFunction('IFNULL', '\\DoctrineExtensions\\Query\\Mysql\\IfNUll'); $config->addCustomStringFunction('MATCHAGAINST', '\\DoctrineExtensions\\Query\\Mysql\\MatchAgainst'); $config->addCustomStringFunction('MONTH', '\\DoctrineExtensions\\Query\\Mysql\\Month'); $config->addCustomStringFunction('NULLIF', '\\DoctrineExtensions\\Query\\Mysql\\NullIf'); $config->addCustomStringFunction('PI', '\\DoctrineExtensions\\Query\\Mysql\\Pi'); $config->addCustomStringFunction('RADIANS', '\\DoctrineExtensions\\Query\\Mysql\\Radians'); $config->addCustomStringFunction('RAND', '\\DoctrineExtensions\\Query\\Mysql\\Rand'); $config->addCustomStringFunction('REGEXP', '\\DoctrineExtensions\\Query\\Mysql\\Regexp'); $config->addCustomStringFunction('ROUND', '\\DoctrineExtensions\\Query\\Mysql\\Round'); $config->addCustomStringFunction('SHA1', '\\DoctrineExtensions\\Query\\Mysql\\Sha1'); $config->addCustomStringFunction('SHA2', '\\DoctrineExtensions\\Query\\Mysql\\Sha2'); $config->addCustomStringFunction('SIN', '\\DoctrineExtensions\\Query\\Mysql\\Sin'); $config->addCustomStringFunction('STRTODATE', '\\DoctrineExtensions\\Query\\Mysql\\StrToDate'); $config->addCustomStringFunction('TAN', '\\DoctrineExtensions\\Query\\Mysql\\Tan'); $config->addCustomStringFunction('TIMESTAMPDIFF', '\\DoctrineExtensions\\Query\\Mysql\\TimestampDiff'); $config->addCustomStringFunction('WEEK', '\\DoctrineExtensions\\Query\\Mysql\\Week'); $config->addCustomStringFunction('YEAR', '\\DoctrineExtensions\\Query\\Mysql\\Year'); if (!defined('ENV') || ENV === \Fraym\Core::ENV_DEVELOPMENT) { $config->setAutoGenerateProxyClasses(true); } $modelDirs = $this->getModuleDirCache(); \Doctrine\Common\Annotations\AnnotationRegistry::registerLoader(function ($class) { return class_exists($class, true); }); $annotationReader = new \Doctrine\Common\Annotations\AnnotationReader(); $this->cachedAnnotationReader = new \Doctrine\Common\Annotations\CachedReader($annotationReader, $cache); $this->annotationDriver = new \Doctrine\ORM\Mapping\Driver\AnnotationDriver($this->cachedAnnotationReader, $modelDirs); /** * Ignore PHP-DI Annotation */ $annotationReader->addGlobalIgnoredName('Injectable'); $annotationReader->addGlobalIgnoredName('Inject'); $config->setMetadataDriverImpl($this->annotationDriver); $config->setQueryCacheImpl($cache); $config->setResultCacheImpl($cache); $config->setProxyDir($applicationDir . DIRECTORY_SEPARATOR . CACHE_DOCTRINE_PROXY_PATH); $config->setProxyNamespace('Proxies'); $this->fetchMode = \PDO::FETCH_OBJ; $tablePrefix = new TablePrefix(DB_TABLE_PREFIX); $this->eventManager = new \Doctrine\Common\EventManager(); $this->eventManager->addEventListener(\Doctrine\ORM\Events::loadClassMetadata, $tablePrefix); $this->entityManager = \Doctrine\ORM\EntityManager::create($this->connectionOptions, $config, $this->eventManager); $this->pdo = $this->entityManager->getConnection(); $this->pdo->getDatabasePlatform()->registerDoctrineTypeMapping('set', 'string'); $driverChain = new \Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain(); \Gedmo\DoctrineExtensions::registerAbstractMappingIntoDriverChainORM($driverChain, $this->cachedAnnotationReader); $this->eventManager->addEventListener([\Doctrine\ORM\Events::preRemove, \Doctrine\ORM\Events::postRemove, \Doctrine\ORM\Events::prePersist, \Doctrine\ORM\Events::postPersist, \Doctrine\ORM\Events::preUpdate, \Doctrine\ORM\Events::postUpdate, \Doctrine\ORM\Events::postLoad, \Doctrine\ORM\Events::onFlush], $this->eventListener); return $this; }