/**
  * @param ApplicationInterface $app
  *
  * @throws \Doctrine\ORM\ORMException
  * @throws \ObjectivePHP\Primitives\Exception
  * @throws \ObjectivePHP\ServicesFactory\Exception
  */
 public function buildEntityManagers(ApplicationInterface $app)
 {
     $entityManagers = $app->getConfig()->subset(Config\EntityManager::class);
     foreach ($entityManagers as $connection => $params) {
         if (isset($params['db'])) {
             $params = $params['db'];
         }
         // normalize if needed
         $entitiesPaths = $params['entities.locations'];
         Collection::cast($entitiesPaths)->each(function (&$path) {
             if (strpos($path, '/') !== 0) {
                 $path = getcwd() . '/' . $path;
             }
         });
         // TODO: handle isDev depending on app config
         $emConfig = Setup::createAnnotationMetadataConfiguration((array) $entitiesPaths, true);
         $emConfig->setNamingStrategy(new UnderscoreNamingStrategy());
         $em = EntityManager::create($params, $emConfig);
         if (!empty($params['mapping_types']) && is_array($params['mapping_types'])) {
             $platform = $em->getConnection()->getDatabasePlatform();
             foreach ($params['mapping_types'] as $type => $mapping) {
                 if (!Type::hasType($type) && class_exists($mapping)) {
                     Type::addType($type, $mapping);
                     $mapping = $type;
                 }
                 $platform->registerDoctrineTypeMapping($type, $mapping);
             }
         }
         // register entity manager as a service
         $emServiceId = 'doctrine.em.' . Str::cast($connection)->lower();
         $app->getServicesFactory()->registerService(['id' => $emServiceId, 'instance' => $em]);
         $app->getServicesFactory()->registerService(['id' => 'db.connection.' . $connection, 'instance' => $em->getConnection()->getWrappedConnection()]);
     }
 }
 protected function setUp()
 {
     parent::setUp();
     if (!Type::hasType('bigfloat')) {
         Type::addType('bigfloat', '\\Psql\\Doctrine\\DBAL\\Types\\BigFloatType');
     }
 }
 /**
  * @test
  */
 public function I_can_register_it_and_specific_choices_by_self()
 {
     ExceptionalityChoiceType::registerAll();
     self::assertTrue(Type::hasType($this->getExpectedTypeName()));
     self::assertTrue(ExceptionalityChoiceType::hasSubTypeEnum(Fortune::class));
     self::assertTrue(ExceptionalityChoiceType::hasSubTypeEnum(PlayerDecision::class));
 }
 /**
  * @test
  */
 public function I_can_register_required_enums_at_once()
 {
     PersonEnumsRegistrar::registerAll();
     self::assertTrue(Type::hasType(RaceType::RACE));
     self::assertTrue(Type::hasType(NameType::NAME));
     // ... and many others
 }
 public function setUp()
 {
     if (!Type::hasType('point')) {
         Type::addType('point', 'CrEOF\\Spatial\\DBAL\\Types\\Geometry\\PointType');
     }
     parent::setUp();
 }
Exemplo n.º 6
0
 public function parseInternal($name, $type, CaseSensor $sensor, $hasName)
 {
     if ($type === 'null') {
         return new VoidDomain();
     }
     if ($type === null || $type === '') {
         $type = Types\Type::STRING;
     }
     if (isset(self::$alias[$type])) {
         $type = self::$alias[$type];
     }
     if (($p = strrpos($type, '[]')) !== false) {
         return new ArrayDomain($this->parseInternal('', substr($type, 0, $p), $sensor, true));
     }
     if ($type === Types\Type::TARRAY) {
         return new AnyArrayDomain(new BuiltinDomain(Types\Type::STRING));
     }
     if (Types\Type::hasType($type)) {
         return new BuiltinDomain($type);
     }
     if (is_subclass_of($type, DomainBase::class)) {
         return $this->parseAsDomain($type, $sensor, $hasName);
     }
     if (class_exists($type)) {
         return self::parseAsEntity(new \ReflectionClass($type), $sensor);
     }
     throw new \Exception("domain not found: ({$type} {$name})");
 }
Exemplo n.º 7
0
 protected function setUp()
 {
     parent::setUp();
     if (!Type::hasType('point')) {
         Type::addType('point', 'Doctrine\\Tests\\Types\\MySqlPointType');
     }
 }
 public function testContainer()
 {
     $container = $this->createYamlBundleTestContainer();
     $this->assertInstanceOf('Doctrine\\DBAL\\Logging\\DebugStack', $container->get('doctrine.dbal.logger.debug'));
     $this->assertInstanceOf('Doctrine\\DBAL\\Logging\\DebugStack', $container->get('doctrine.dbal.logger'));
     $this->assertInstanceOf('Symfony\\Bundle\\DoctrineBundle\\DataCollector\\DoctrineDataCollector', $container->get('data_collector.doctrine'));
     $this->assertInstanceOf('Doctrine\\DBAL\\Configuration', $container->get('doctrine.dbal.default_connection.configuration'));
     $this->assertInstanceOf('Doctrine\\Common\\EventManager', $container->get('doctrine.dbal.default_connection.event_manager'));
     $this->assertInstanceOf('Doctrine\\DBAL\\Connection', $container->get('doctrine.dbal.default_connection'));
     $this->assertInstanceOf('Doctrine\\Common\\Annotations\\AnnotationReader', $container->get('doctrine.orm.metadata.annotation_reader'));
     $this->assertInstanceOf('Doctrine\\ORM\\Configuration', $container->get('doctrine.orm.default_configuration'));
     $this->assertInstanceOf('Doctrine\\ORM\\Mapping\\Driver\\DriverChain', $container->get('doctrine.orm.default_metadata_driver'));
     $this->assertInstanceOf('Doctrine\\Common\\Cache\\ArrayCache', $container->get('doctrine.orm.default_metadata_cache'));
     $this->assertInstanceOf('Doctrine\\Common\\Cache\\ArrayCache', $container->get('doctrine.orm.default_query_cache'));
     $this->assertInstanceOf('Doctrine\\Common\\Cache\\ArrayCache', $container->get('doctrine.orm.default_result_cache'));
     $this->assertInstanceOf('Doctrine\\ORM\\EntityManager', $container->get('doctrine.orm.default_entity_manager'));
     $this->assertInstanceOf('Doctrine\\DBAL\\Connection', $container->get('database_connection'));
     $this->assertInstanceOf('Doctrine\\ORM\\EntityManager', $container->get('doctrine.orm.entity_manager'));
     $this->assertInstanceOf('Doctrine\\Common\\EventManager', $container->get('doctrine.orm.default_entity_manager.event_manager'));
     $this->assertInstanceOf('Doctrine\\Common\\EventManager', $container->get('doctrine.dbal.event_manager'));
     $this->assertInstanceOf('Doctrine\\DBAL\\Event\\Listeners\\MysqlSessionInit', $container->get('doctrine.dbal.default_connection.events.mysqlsessioninit'));
     $this->assertInstanceOf('Symfony\\Bundle\\DoctrineBundle\\CacheWarmer\\ProxyCacheWarmer', $container->get('doctrine.orm.proxy_cache_warmer'));
     $this->assertSame($container->get('my.platform'), $container->get('doctrine.dbal.default_connection')->getDatabasePlatform());
     $this->assertTrue(Type::hasType('test'));
 }
 public function boot()
 {
     if (!Type::hasType('string_simple_array')) {
         // this should be optional if using a different ORM
         Type::addType('string_simple_array', 'Giosh94mhz\\GeonamesBundle\\Doctrine\\Types\\StringSimpleArrayType');
     }
 }
Exemplo n.º 10
0
 public function testContainer()
 {
     $container = $this->createYamlBundleTestContainer();
     $this->assertInstanceOf('Symfony\\Bridge\\Doctrine\\Logger\\DbalLogger', $container->get('doctrine.dbal.logger'));
     $this->assertInstanceOf('Symfony\\Bridge\\Doctrine\\DataCollector\\DoctrineDataCollector', $container->get('data_collector.doctrine'));
     $this->assertInstanceOf('Doctrine\\DBAL\\Configuration', $container->get('doctrine.dbal.default_connection.configuration'));
     $this->assertInstanceOf('Doctrine\\Common\\EventManager', $container->get('doctrine.dbal.default_connection.event_manager'));
     $this->assertInstanceOf('Doctrine\\DBAL\\Connection', $container->get('doctrine.dbal.default_connection'));
     $this->assertInstanceOf('Doctrine\\Common\\Annotations\\Reader', $container->get('doctrine.orm.metadata.annotation_reader'));
     $this->assertInstanceOf('Doctrine\\ORM\\Configuration', $container->get('doctrine.orm.default_configuration'));
     $this->assertInstanceOf('Doctrine\\ORM\\Mapping\\Driver\\DriverChain', $container->get('doctrine.orm.default_metadata_driver'));
     $this->assertInstanceOf('Doctrine\\Common\\Cache\\ArrayCache', $container->get('doctrine.orm.default_metadata_cache'));
     $this->assertInstanceOf('Doctrine\\Common\\Cache\\ArrayCache', $container->get('doctrine.orm.default_query_cache'));
     $this->assertInstanceOf('Doctrine\\Common\\Cache\\ArrayCache', $container->get('doctrine.orm.default_result_cache'));
     $this->assertInstanceOf('Doctrine\\ORM\\EntityManager', $container->get('doctrine.orm.default_entity_manager'));
     $this->assertInstanceOf('Doctrine\\DBAL\\Connection', $container->get('database_connection'));
     $this->assertInstanceOf('Doctrine\\ORM\\EntityManager', $container->get('doctrine.orm.entity_manager'));
     $this->assertInstanceOf('Doctrine\\Common\\EventManager', $container->get('doctrine.orm.default_entity_manager.event_manager'));
     $this->assertInstanceOf('Doctrine\\Common\\EventManager', $container->get('doctrine.dbal.event_manager'));
     $this->assertInstanceOf('Symfony\\Bridge\\Doctrine\\CacheWarmer\\ProxyCacheWarmer', $container->get('doctrine.orm.proxy_cache_warmer'));
     $this->assertInstanceOf('Doctrine\\Common\\Persistence\\ManagerRegistry', $container->get('doctrine'));
     $this->assertInstanceOf('Symfony\\Bridge\\Doctrine\\Validator\\Constraints\\UniqueEntityValidator', $container->get('doctrine.orm.validator.unique'));
     $this->assertSame($container->get('my.platform'), $container->get('doctrine.dbal.default_connection')->getDatabasePlatform());
     $this->assertTrue(Type::hasType('test'));
     if (version_compare(PHP_VERSION, '5.3.6', '<')) {
         $this->assertInstanceOf('Doctrine\\DBAL\\Event\\Listeners\\MysqlSessionInit', $container->get('doctrine.dbal.default_connection.events.mysqlsessioninit'));
     } else {
         $this->assertFalse($container->has('doctrine.dbal.default_connection.events.mysqlsessioninit'));
     }
 }
 protected function setUp()
 {
     if (!Type::hasType(PercentType::TYPE)) {
         Type::addType(PercentType::TYPE, 'Oro\\DBAL\\Types\\PercentType');
     }
     $this->percentType = Type::getType(PercentType::TYPE);
 }
 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);
 }
Exemplo n.º 13
0
 /**
  * Defines new custom types to be supported by Doctrine
  *
  * @param array $types Key-value map of types to include
  * @param boolean $override Optional flag to support only inclusion or also override
  */
 public function setCustomTypes(array $types, $override = false)
 {
     foreach ($types as $name => $typeClassName) {
         $method = (Type::hasType($name) && $override ? 'override' : 'add') . 'Type';
         Type::$method($name, $typeClassName);
     }
 }
 public function __construct()
 {
     //TODO its not fine
     if (!Type::hasType('genderEnumType')) {
         Type::addType('genderEnumType', 'Network\\StoreBundle\\DBAL\\GenderEnumType');
     }
     if (!Type::hasType('roleEnumType')) {
         Type::addType('roleEnumType', 'Network\\StoreBundle\\DBAL\\RoleEnumType');
     }
     if (!Type::hasType('relationshipStatusEnumType')) {
         Type::addType('relationshipStatusEnumType', 'Network\\StoreBundle\\DBAL\\RelationshipStatusEnumType');
     }
     if (!Type::hasType('roleCommunityEnumType')) {
         Type::addType('roleCommunityEnumType', 'Network\\StoreBundle\\DBAL\\RoleCommunityEnumType');
     }
     if (!Type::hasType('viewCommunityEnumType')) {
         Type::addType('viewCommunityEnumType', 'Network\\StoreBundle\\DBAL\\ViewCommunityEnumType');
     }
     if (!Type::hasType('typeCommunityEnumType')) {
         Type::addType('typeCommunityEnumType', 'Network\\StoreBundle\\DBAL\\TypeCommunityEnumType');
     }
     if (!Type::hasType('threadEnumType')) {
         Type::addType('threadEnumType', 'Network\\StoreBundle\\DBAL\\ThreadEnumType');
     }
     if (!Type::hasType('typePostEnumType')) {
         Type::addType('typePostEnumType', 'Network\\StoreBundle\\DBAL\\TypePostEnumType');
     }
 }
 public function boot()
 {
     if (!Type::hasType('branch_logo')) {
         Type::addType('branch_logo', 'Diamante\\DeskBundle\\Infrastructure\\Persistence\\Doctrine\\DBAL\\Types\\BranchLogoType');
     }
     if (!Type::hasType('priority')) {
         Type::addType('priority', 'Diamante\\DeskBundle\\Infrastructure\\Persistence\\Doctrine\\DBAL\\Types\\TicketPriorityType');
     }
     if (!Type::hasType('file')) {
         Type::addType('file', 'Diamante\\DeskBundle\\Infrastructure\\Persistence\\Doctrine\\DBAL\\Types\\AttachmentFileType');
     }
     if (!Type::hasType('status')) {
         Type::addType('status', 'Diamante\\DeskBundle\\Infrastructure\\Persistence\\Doctrine\\DBAL\\Types\\TicketStatusType');
     }
     if (!Type::hasType('source')) {
         Type::addType('source', 'Diamante\\DeskBundle\\Infrastructure\\Persistence\\Doctrine\\DBAL\\Types\\TicketSourceType');
     }
     if (!Type::hasType('ticket_sequence_number')) {
         Type::addType('ticket_sequence_number', 'Diamante\\DeskBundle\\Infrastructure\\Persistence\\Doctrine\\DBAL\\Types\\TicketSequenceNumberType');
     }
     if (!Type::hasType('ticket_unique_id')) {
         Type::addType('ticket_unique_id', 'Diamante\\DeskBundle\\Infrastructure\\Persistence\\Doctrine\\DBAL\\Types\\TicketUniqueIdType');
     }
     foreach ($this->dataAuditTypes as $type) {
         if (!AuditFieldTypeRegistry::hasType($type)) {
             AuditFieldTypeRegistry::addType($type, $type);
         }
     }
     $em = $this->container->get('doctrine.orm.default_entity_manager');
     $conn = $em->getConnection();
     $conn->getDatabasePlatform()->registerDoctrineTypeMapping('FILE', 'string');
 }
 public function boot()
 {
     if (false === Type::hasType(ExtendedDataType::NAME)) {
         ExtendedDataType::setEncryptionService($this->container->get('payment.encryption_service'));
         Type::addType(ExtendedDataType::NAME, 'JMS\\Payment\\CoreBundle\\Entity\\ExtendedDataType');
     }
 }
 protected function setUp()
 {
     $enumTypeClass = $this->getTypeClass();
     if (!Type::hasType($this->getExpectedTypeName())) {
         Type::addType($this->getExpectedTypeName(), $enumTypeClass);
     }
 }
Exemplo n.º 18
0
 protected function setUp()
 {
     if (!Type::hasType('money')) {
         Type::addType('money', 'CSBill\\MoneyBundle\\Doctrine\\Types\\MoneyType');
         MoneyType::setCurrency(new Currency('USD'));
     }
 }
 function let()
 {
     if (!Type::hasType(GeographicLocationType::NAME)) {
         Type::addType(GeographicLocationType::NAME, 'DoctrineExt\\DBAL\\Types\\GeographicLocationType');
     }
     $this->beConstructedThrough('getType', [GeographicLocationType::NAME]);
 }
 /**
  * @test
  */
 public function I_can_register_all_codes_at_once()
 {
     $typeName = $this->getExpectedTypeName();
     self::assertFalse(Type::hasType($typeName), "Type of name '{$typeName}' should not be registered yet");
     /** @var ScalarEnumType $typeClass */
     $typeClass = $this->getTypeClass();
     foreach ($this->getRelatedCodeClasses() as $relatedCodeClass) {
         self::assertFalse($typeClass::hasSubTypeEnum($relatedCodeClass), "Sub-type enum of a class '{$relatedCodeClass}' should not be registered yet");
     }
     $typeClass::registerSelf();
     self::assertTrue(Type::hasType($typeName), "Type of name '{$typeName}' is not registered");
     $testedType = Type::getType($typeName);
     $platform = $this->createPlatform();
     foreach ($this->getRelatedCodeClasses() as $relatedCodeClass) {
         self::assertTrue($typeClass::hasSubTypeEnum($relatedCodeClass), "Sub-type enum of a class '{$relatedCodeClass}' is not registered");
         foreach ($relatedCodeClass::getPossibleValues() as $possibleValue) {
             $asPhp = $testedType->convertToPHPValue($relatedCodeClass . '::' . $possibleValue, $platform);
             self::assertInstanceOf($relatedCodeClass, $asPhp);
             /** @var AbstractCode $asPhp */
             self::assertSame($possibleValue, $asPhp->getValue());
         }
     }
     $typeClass::registerSelf();
     // test if can call registering repeatedly
 }
 /**
  * Adds doctrine point type
  *
  * @param LoadClassMetadataEventArgs $eventArgs
  */
 public function loadClassMetadata(LoadClassMetadataEventArgs $eventArgs)
 {
     $classMetadata = $eventArgs->getClassMetadata();
     if (null === $classMetadata->reflClass) {
         return;
     }
     if ($this->isGeocodable($classMetadata)) {
         if (!Type::hasType('point')) {
             Type::addType('point', 'Knp\\DoctrineBehaviors\\DBAL\\Types\\PointType');
         }
         $em = $eventArgs->getEntityManager();
         $con = $em->getConnection();
         // skip non-postgres platforms
         if (!$con->getDatabasePlatform() instanceof PostgreSqlPlatform && !$con->getDatabasePlatform() instanceof MySqlPlatform) {
             return;
         }
         // skip platforms with registerd stuff
         if (!$con->getDatabasePlatform()->hasDoctrineTypeMappingFor('point')) {
             $con->getDatabasePlatform()->registerDoctrineTypeMapping('point', 'point');
             if ($con->getDatabasePlatform() instanceof PostgreSqlPlatform) {
                 $em->getConfiguration()->addCustomNumericFunction('DISTANCE', 'Knp\\DoctrineBehaviors\\ORM\\Geocodable\\Query\\AST\\Functions\\DistanceFunction');
             }
         }
         $classMetadata->mapField(['fieldName' => 'location', 'type' => 'point', 'nullable' => true]);
     }
 }
 function let()
 {
     $type = LdapObjectType::TYPE;
     if (!Type::hasType($type)) {
         Type::addType($type, '\\LdapTools\\Bundle\\LdapToolsBundle\\Doctrine\\Type\\LdapObjectType');
     }
     $this->beConstructedThrough('getType', [$type]);
 }
Exemplo n.º 23
0
 public function __construct(DisconnectedClassMetadataFactory $cmf)
 {
     $this->cmf = $cmf;
     //allow sonata type 'json'
     if (!\Doctrine\DBAL\Types\Type::hasType('json')) {
         \Doctrine\DBAL\Types\Type::addType('json', 'Sonata\\Doctrine\\Types\\JsonType');
     }
 }
Exemplo n.º 24
0
 protected function setUp()
 {
     $this->_platform = new MockPlatform();
     if (!Type::hasType('vardatetime')) {
         Type::addType('vardatetime', 'Doctrine\\DBAL\\Types\\VarDateTimeType');
     }
     $this->_type = Type::getType('vardatetime');
 }
Exemplo n.º 25
0
 protected function setUp()
 {
     if (!Type::hasType($this->typeName)) {
         Type::addType($this->typeName, $this->typeClass);
     }
     $this->type = Type::getType($this->typeName);
     $this->platform = new PostgreSqlPlatform();
 }
Exemplo n.º 26
0
 public function setUp()
 {
     if (Type::hasType('currency')) {
         Type::overrideType('currency', 'Sonata\\Component\\Currency\\CurrencyDoctrineType');
     } else {
         Type::addType('currency', 'Sonata\\Component\\Currency\\CurrencyDoctrineType');
     }
 }
Exemplo n.º 27
0
 /**
  * @param $name
  * @param $class
  *
  * @throws \Doctrine\DBAL\DBALException
  */
 public function addType($name, $class)
 {
     if (!Type::hasType($name)) {
         Type::addType($name, $class);
     } else {
         Type::overrideType($name, $class);
     }
 }
Exemplo n.º 28
0
 public function setUp()
 {
     if (Type::hasType('json')) {
         Type::overrideType('json', 'Sonata\\Doctrine\\Types\\JsonType');
     } else {
         Type::addType('json', 'Sonata\\Doctrine\\Types\\JsonType');
     }
 }
 /**
  * @test
  */
 public function I_can_register_all_enums_at_once()
 {
     PersonBackgroundEnumRegistrar::registerAll();
     self::assertTrue(Type::hasType(BackgroundPointsType::BACKGROUND_POINTS));
     self::assertTrue(Type::hasType(BackgroundSkillPointsType::BACKGROUND_SKILL_POINTS));
     self::assertTrue(Type::hasType(BelongingsValueType::BELONGINGS_VALUE));
     self::assertTrue(Type::hasType(HeritageType::HERITAGE));
 }
 public function __construct()
 {
     AnnotationRegistry::registerAutoloadNamespace(self::ANNOTATION_NS);
     $this->reader = new AnnotationReader();
     if (!Type::hasType(strtolower(self::ANNOTATION_TSVECTOR))) {
         Type::addType(strtolower(self::ANNOTATION_TSVECTOR), TsVectorType::class);
     }
 }