88use Flow \Bridge \Symfony \PostgreSqlBundle \Attribute \AsCatalogProvider ;
99use Flow \Bridge \Symfony \PostgreSqlBundle \CatalogProvider \ArrayCatalogProvider ;
1010use Flow \Bridge \Symfony \PostgreSqlBundle \Command \SessionPurgeCommand ;
11+ use Flow \Bridge \Symfony \PostgreSqlBundle \Connection \ConnectionParametersFactory ;
1112use Flow \Bridge \Symfony \PostgreSqlBundle \DependencyInjection \Compiler \CatalogProviderPass ;
1213use Flow \Bridge \Symfony \PostgreSqlBundle \DependencyInjection \Compiler \CommandLocatorPass ;
1314use Flow \Bridge \Symfony \PostgreSqlBundle \Generator \TwigMigrationGenerator ;
@@ -107,6 +108,30 @@ public function configure(DefinitionConfigurator $definition): void
107108 ->cannotBeEmpty ()
108109 ->info ('PostgreSQL connection DSN (e.g. postgresql://user:pass@localhost:5432/dbname) ' )
109110 ->end ()
111+ ->scalarNode ('dbname ' )
112+ ->defaultNull ()
113+ ->info ('Overrides the database name parsed from the DSN. ' )
114+ ->end ()
115+ ->scalarNode ('host ' )
116+ ->defaultNull ()
117+ ->info ('Overrides the host parsed from the DSN. ' )
118+ ->end ()
119+ ->integerNode ('port ' )
120+ ->defaultNull ()
121+ ->info ('Overrides the port parsed from the DSN. ' )
122+ ->end ()
123+ ->scalarNode ('user ' )
124+ ->defaultNull ()
125+ ->info ('Overrides the user parsed from the DSN. ' )
126+ ->end ()
127+ ->scalarNode ('password ' )
128+ ->defaultNull ()
129+ ->info ('Overrides the password parsed from the DSN. ' )
130+ ->end ()
131+ ->scalarNode ('dbname_suffix ' )
132+ ->defaultValue ('' )
133+ ->info ('Adds the given suffix to the configured database name. ' )
134+ ->end ()
110135 ->booleanNode ('test_transaction_rollback ' )
111136 ->defaultFalse ()
112137 ->info (
@@ -399,7 +424,7 @@ public function configure(DefinitionConfigurator $definition): void
399424 }
400425
401426 /**
402- * @param array{connections: array<string, array{dsn: string, test_transaction_rollback: bool, context?: array<string, mixed>, telemetry?: array{service_id: string, clock_service_id: ?string, trace_queries: bool, trace_transactions: bool, collect_metrics: bool, log_queries: bool, max_query_length: int, include_parameters: bool, max_parameters: int, max_parameter_length: int}}>, messenger: array{enabled: bool, table_name: string, schema: string}, cache: array{pools?: array<string, array{connection: ?string, table_name: string, schema: string, id_col: string, data_col: string, lifetime_col: string, time_col: string, namespace: string, default_lifetime: int, marshaller_service_id: ?string, share_connection: bool}>}, session: array{enabled: bool, connection: ?string, table_name: string, schema: string, id_col: string, data_col: string, lifetime_col: string, time_col: string, lock_mode: string, ttl: ?int, share_connection: bool}, migrations: array{enabled: bool, directory: string, namespace: string, table_name: string, table_schema: string, migration_file_name: string, rollback_file_name: string, all_or_nothing: bool, generate_rollback: bool, exclude?: list<array{schema: ?string, table: ?string, exact: ?string, starts_with: ?string, ends_with: ?string, pattern: ?string, policy_id: ?string, type: ?string, for_schema: ?string}>}, catalog_providers: list<array{catalog_provider_id: ?string, catalog: ?array<string, mixed>}>} $config
427+ * @param array{connections: array<string, array{dsn: string, dbname: ?string, host: ?string, port: ?int, user: ?string, password: ?string, dbname_suffix: string, test_transaction_rollback: bool, context?: array<string, mixed>, telemetry?: array{service_id: string, clock_service_id: ?string, trace_queries: bool, trace_transactions: bool, collect_metrics: bool, log_queries: bool, max_query_length: int, include_parameters: bool, max_parameters: int, max_parameter_length: int}}>, messenger: array{enabled: bool, table_name: string, schema: string}, cache: array{pools?: array<string, array{connection: ?string, table_name: string, schema: string, id_col: string, data_col: string, lifetime_col: string, time_col: string, namespace: string, default_lifetime: int, marshaller_service_id: ?string, share_connection: bool}>}, session: array{enabled: bool, connection: ?string, table_name: string, schema: string, id_col: string, data_col: string, lifetime_col: string, time_col: string, lock_mode: string, ttl: ?int, share_connection: bool}, migrations: array{enabled: bool, directory: string, namespace: string, table_name: string, table_schema: string, migration_file_name: string, rollback_file_name: string, all_or_nothing: bool, generate_rollback: bool, exclude?: list<array{schema: ?string, table: ?string, exact: ?string, starts_with: ?string, ends_with: ?string, pattern: ?string, policy_id: ?string, type: ?string, for_schema: ?string}>}, catalog_providers: list<array{catalog_provider_id: ?string, catalog: ?array<string, mixed>}>} $config
403428 */
404429 #[Override]
405430 public function loadExtension (array $ config , ContainerConfigurator $ configurator , ContainerBuilder $ container ): void
@@ -537,7 +562,7 @@ private function registerCatalogProviders(array $catalogProviders, ContainerBuil
537562 }
538563
539564 /**
540- * @param array{dsn: string, test_transaction_rollback: bool, context?: array<string, mixed>, telemetry?: array{service_id: string, clock_service_id: ?string, trace_queries: bool, trace_transactions: bool, collect_metrics: bool, log_queries: bool, max_query_length: int, include_parameters: bool, max_parameters: int, max_parameter_length: int}} $connectionConfig
565+ * @param array{dsn: string, dbname: ?string, host: ?string, port: ?int, user: ?string, password: ?string, dbname_suffix: string, test_transaction_rollback: bool, context?: array<string, mixed>, telemetry?: array{service_id: string, clock_service_id: ?string, trace_queries: bool, trace_transactions: bool, collect_metrics: bool, log_queries: bool, max_query_length: int, include_parameters: bool, max_parameters: int, max_parameter_length: int}} $connectionConfig
541566 */
542567 private function registerConnection (
543568 string $ name ,
@@ -549,8 +574,19 @@ private function registerConnection(
549574 $ container ->setDefinition ("flow.postgresql. {$ name }.dsn_parser " , $ parserDef );
550575
551576 $ paramsDef = new Definition (ConnectionParameters::class);
552- $ paramsDef ->setFactory ([new Reference ("flow.postgresql. {$ name }.dsn_parser " ), 'parse ' ]);
553- $ paramsDef ->setArguments ([$ connectionConfig ['dsn ' ]]);
577+ $ paramsDef ->setFactory ([ConnectionParametersFactory::class, 'create ' ]);
578+ $ paramsDef ->setArguments ([
579+ new Reference ("flow.postgresql. {$ name }.dsn_parser " ),
580+ $ connectionConfig ['dsn ' ],
581+ [
582+ 'dbname ' => $ connectionConfig ['dbname ' ] ?? null ,
583+ 'host ' => $ connectionConfig ['host ' ] ?? null ,
584+ 'port ' => $ connectionConfig ['port ' ] ?? null ,
585+ 'user ' => $ connectionConfig ['user ' ] ?? null ,
586+ 'password ' => $ connectionConfig ['password ' ] ?? null ,
587+ 'dbname_suffix ' => $ connectionConfig ['dbname_suffix ' ] ?? '' ,
588+ ],
589+ ]);
554590 $ container ->setDefinition ("flow.postgresql. {$ name }.connection_parameters " , $ paramsDef );
555591
556592 $ paramsDef ->setPublic (true );
0 commit comments