@@ -167,26 +167,26 @@ private function registerCommonConfiguration(ContainerBuilder $container, array
167
167
$ container ->setParameter ('api_platform.eager_loading.fetch_partial ' , $ config ['eager_loading ' ]['fetch_partial ' ]);
168
168
$ container ->setParameter ('api_platform.eager_loading.force_eager ' , $ config ['eager_loading ' ]['force_eager ' ]);
169
169
$ container ->setParameter ('api_platform.collection.exists_parameter_name ' , $ config ['collection ' ]['exists_parameter_name ' ]);
170
- $ container ->setParameter ('api_platform.collection.order ' , $ config ['collection ' ]['order ' ]);
170
+ $ container ->setParameter ('api_platform.collection.order ' , $ config ['defaults ' ][ ' order ' ] ?? $ config [ ' collection ' ]['order ' ]);
171
171
$ container ->setParameter ('api_platform.collection.order_parameter_name ' , $ config ['collection ' ]['order_parameter_name ' ]);
172
- $ container ->setParameter ('api_platform.collection.pagination.enabled ' , $ this ->isConfigEnabled ($ container , $ config ['collection ' ]['pagination ' ]));
173
- $ container ->setParameter ('api_platform.collection.pagination.partial ' , $ config ['collection ' ]['pagination ' ]['partial ' ]);
174
- $ container ->setParameter ('api_platform.collection.pagination.client_enabled ' , $ config ['collection ' ]['pagination ' ]['client_enabled ' ]);
175
- $ container ->setParameter ('api_platform.collection.pagination.client_items_per_page ' , $ config ['collection ' ]['pagination ' ]['client_items_per_page ' ]);
176
- $ container ->setParameter ('api_platform.collection.pagination.client_partial ' , $ config ['collection ' ]['pagination ' ]['client_partial ' ]);
177
- $ container ->setParameter ('api_platform.collection.pagination.items_per_page ' , $ config ['collection ' ]['pagination ' ]['items_per_page ' ]);
178
- $ container ->setParameter ('api_platform.collection.pagination.maximum_items_per_page ' , $ config ['collection ' ]['pagination ' ]['maximum_items_per_page ' ]);
179
- $ container ->setParameter ('api_platform.collection.pagination.page_parameter_name ' , $ config ['collection ' ]['pagination ' ]['page_parameter_name ' ]);
180
- $ container ->setParameter ('api_platform.collection.pagination.enabled_parameter_name ' , $ config ['collection ' ]['pagination ' ]['enabled_parameter_name ' ]);
181
- $ container ->setParameter ('api_platform.collection.pagination.items_per_page_parameter_name ' , $ config ['collection ' ]['pagination ' ]['items_per_page_parameter_name ' ]);
182
- $ container ->setParameter ('api_platform.collection.pagination.partial_parameter_name ' , $ config ['collection ' ]['pagination ' ]['partial_parameter_name ' ]);
183
- $ container ->setParameter ('api_platform.collection.pagination ' , $ config ['collection ' ]['pagination ' ]);
184
- $ container ->setParameter ('api_platform.http_cache.etag ' , $ config ['http_cache ' ]['etag ' ]);
185
- $ container ->setParameter ('api_platform.http_cache.max_age ' , $ config ['http_cache ' ]['max_age ' ]);
186
- $ container ->setParameter ('api_platform.http_cache.shared_max_age ' , $ config ['http_cache ' ]['shared_max_age ' ]);
187
- $ container ->setParameter ('api_platform.http_cache.vary ' , $ config ['http_cache ' ]['vary ' ]);
188
- $ container ->setParameter ('api_platform.http_cache.public ' , $ config ['http_cache ' ]['public ' ]);
189
- $ container ->setParameter ('api_platform.http_cache.invalidation.max_header_length ' , $ config ['http_cache ' ]['invalidation ' ]['max_header_length ' ]);
172
+ $ container ->setParameter ('api_platform.collection.pagination.enabled ' , $ this ->isConfigEnabled ($ container , $ config ['defaults ' ][ ' pagination_enabled ' ] ?? $ config [ ' collection ' ]['pagination ' ]));
173
+ $ container ->setParameter ('api_platform.collection.pagination.partial ' , $ config ['defaults ' ][ ' pagination_partial ' ] ?? $ config [ ' collection ' ]['pagination ' ]['partial ' ]);
174
+ $ container ->setParameter ('api_platform.collection.pagination.client_enabled ' , $ config ['defaults ' ][ ' pagination_client_enabled ' ] ?? $ config [ ' collection ' ]['pagination ' ]['client_enabled ' ]);
175
+ $ container ->setParameter ('api_platform.collection.pagination.client_items_per_page ' , $ config ['defaults ' ][ ' pagination_client_items_per_page ' ] ?? $ config [ ' collection ' ]['pagination ' ]['client_items_per_page ' ]);
176
+ $ container ->setParameter ('api_platform.collection.pagination.client_partial ' , $ config ['defaults ' ][ ' pagination_client_partial ' ] ?? $ config [ ' collection ' ]['pagination ' ]['client_partial ' ]);
177
+ $ container ->setParameter ('api_platform.collection.pagination.items_per_page ' , $ config ['defaults ' ][ ' pagination_items_per_page ' ] ?? $ config [ ' collection ' ]['pagination ' ]['items_per_page ' ]);
178
+ $ container ->setParameter ('api_platform.collection.pagination.maximum_items_per_page ' , $ config ['defaults ' ][ ' pagination_maximum_items_per_page ' ] ?? $ config [ ' collection ' ]['pagination ' ]['maximum_items_per_page ' ]);
179
+ $ container ->setParameter ('api_platform.collection.pagination.page_parameter_name ' , $ config ['defaults ' ][ ' pagination_page_parameter_name ' ] ?? $ config [ ' collection ' ]['pagination ' ]['page_parameter_name ' ]);
180
+ $ container ->setParameter ('api_platform.collection.pagination.enabled_parameter_name ' , $ config ['defaults ' ][ ' pagination_enabled_parameter_name ' ] ?? $ config [ ' collection ' ]['pagination ' ]['enabled_parameter_name ' ]);
181
+ $ container ->setParameter ('api_platform.collection.pagination.items_per_page_parameter_name ' , $ config ['defaults ' ][ ' pagination_items_per_page_parameter_name ' ] ?? $ config [ ' collection ' ]['pagination ' ]['items_per_page_parameter_name ' ]);
182
+ $ container ->setParameter ('api_platform.collection.pagination.partial_parameter_name ' , $ config ['defaults ' ][ ' pagination_partial_parameter_name ' ] ?? $ config [ ' collection ' ]['pagination ' ]['partial_parameter_name ' ]);
183
+ $ container ->setParameter ('api_platform.collection.pagination ' , $ this -> getPaginationDefaults ( $ config ['defaults ' ], $ config [ ' collection ' ]['pagination ' ]) );
184
+ $ container ->setParameter ('api_platform.http_cache.etag ' , $ config ['defaults ' ][ ' cache_headers ' ][ ' etag ' ] ?? $ config [ ' http_cache ' ]['etag ' ]);
185
+ $ container ->setParameter ('api_platform.http_cache.max_age ' , $ config ['defaults ' ][ ' cache_headers ' ][ ' max_age ' ] ?? $ config [ ' http_cache ' ]['max_age ' ]);
186
+ $ container ->setParameter ('api_platform.http_cache.shared_max_age ' , $ config ['defaults ' ][ ' cache_headers ' ][ ' shared_max_age ' ] ?? $ config [ ' http_cache ' ]['shared_max_age ' ]);
187
+ $ container ->setParameter ('api_platform.http_cache.vary ' , $ config ['defaults ' ][ ' cache_headers ' ][ ' vary ' ] ?? $ config [ ' http_cache ' ]['vary ' ]);
188
+ $ container ->setParameter ('api_platform.http_cache.public ' , $ config ['defaults ' ][ ' cache_headers ' ][ ' public ' ] ?? $ config [ ' http_cache ' ]['public ' ]);
189
+ $ container ->setParameter ('api_platform.http_cache.invalidation.max_header_length ' , $ config ['defaults ' ][ ' cache_headers ' ][ ' invalidation ' ][ ' max_header_length ' ] ?? $ config [ ' http_cache ' ]['invalidation ' ]['max_header_length ' ]);
190
190
191
191
$ container ->setAlias ('api_platform.operation_path_resolver.default ' , $ config ['default_operation_path_resolver ' ]);
192
192
$ container ->setAlias ('api_platform.path_segment_name_generator ' , $ config ['path_segment_name_generator ' ]);
@@ -197,6 +197,24 @@ private function registerCommonConfiguration(ContainerBuilder $container, array
197
197
$ container ->setParameter ('api_platform.defaults ' , $ this ->normalizeDefaults ($ config ['defaults ' ] ?? []));
198
198
}
199
199
200
+ /**
201
+ * This method will be removed in 3.0 when "defaults" will be the regular configuration path for the pagination.
202
+ */
203
+ private function getPaginationDefaults (array $ defaults , array $ collectionPaginationConfiguration ): array
204
+ {
205
+ $ paginationOptions = [];
206
+
207
+ foreach ($ defaults as $ key => $ value ) {
208
+ if (0 !== strpos ($ key , 'pagination_ ' )) {
209
+ continue ;
210
+ }
211
+
212
+ $ paginationOptions [str_replace ('pagination_ ' , '' , $ key )] = $ value ;
213
+ }
214
+
215
+ return array_merge ($ collectionPaginationConfiguration , $ paginationOptions );
216
+ }
217
+
200
218
private function normalizeDefaults (array $ defaults ): array
201
219
{
202
220
$ normalizedDefaults = ['attributes ' => []];
0 commit comments