Skip to content

Commit b31ef35

Browse files
committed
bug #911 More precisely initializing services/config for asset mapper (weaverryan)
This PR was squashed before being merged into the 2.x branch. Discussion ---------- More precisely initializing services/config for asset mapper | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | Tickets | Fix #907 | License | MIT Hi! A few fixes for the new 2.9 version, which included a lot of under-the-hood changes to support asset mapper. These shouldn't be noticed by users and hopefully this will smooth out the final bumps: A) Avoid prepending the `asset_mapper` config unless FWBundle 6.3 is present. I don't love the solution - but it should work well enough, especially as this applies to asset mapper users and that is still experimental. B) Avoid registering a few asset mapper services that, on older versions of PHP/Symfony, may cause a container explosion due to a trait that won't be present. C) Plug some holes in the CI to test lower deps. The CI really needs to become much more dynamic than it is now, but this makes sure that all packages are tested for highest/lowest deps. Cheers! Commits ------- 34e7ec1 More precisely initializing services/config for asset mapper
2 parents cec9422 + 34e7ec1 commit b31ef35

File tree

23 files changed

+352
-55
lines changed

23 files changed

+352
-55
lines changed

.github/workflows/test.yaml

Lines changed: 66 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ jobs:
6767
echo "${{ steps.changes.outputs.STATUS }}"
6868
exit 1
6969
70-
tests-php-low-deps:
70+
tests-php72-low-deps:
7171
runs-on: ubuntu-latest
7272
steps:
7373
- uses: actions/checkout@master
@@ -102,7 +102,7 @@ jobs:
102102
run: php vendor/bin/simple-phpunit
103103
working-directory: src/LazyImage
104104

105-
tests-php8-low-deps:
105+
tests-php80-low-deps:
106106
runs-on: ubuntu-latest
107107
steps:
108108
- uses: actions/checkout@master
@@ -147,7 +147,7 @@ jobs:
147147
- name: Translator Tests
148148
run: php vendor/bin/simple-phpunit
149149
working-directory: src/Translator
150-
tests-php-high-deps:
150+
tests-php80-high-deps:
151151
runs-on: ubuntu-latest
152152
steps:
153153
- uses: actions/checkout@master
@@ -279,6 +279,69 @@ jobs:
279279
run: php vendor/bin/simple-phpunit
280280
working-directory: src/Vue
281281

282+
tests-php81-low-deps:
283+
runs-on: ubuntu-latest
284+
steps:
285+
- uses: actions/checkout@master
286+
287+
- uses: shivammathur/setup-php@v2
288+
with:
289+
php-version: '8.1'
290+
291+
- name: Chartjs Dependencies
292+
uses: ramsey/composer-install@v2
293+
with:
294+
working-directory: src/Chartjs
295+
dependency-versions: lowest
296+
- name: Chartjs Tests
297+
working-directory: src/Chartjs
298+
run: php vendor/bin/simple-phpunit
299+
300+
- name: Notify Dependencies
301+
uses: ramsey/composer-install@v2
302+
with:
303+
working-directory: src/Notify
304+
dependency-versions: lowest
305+
- name: Notify Tests
306+
working-directory: src/Notify
307+
run: php vendor/bin/simple-phpunit
308+
309+
- name: React Dependencies
310+
uses: ramsey/composer-install@v2
311+
with:
312+
working-directory: src/React
313+
dependency-versions: lowest
314+
- name: React Tests
315+
run: php vendor/bin/simple-phpunit
316+
working-directory: src/React
317+
318+
- name: StimulusBundle Dependencies
319+
uses: ramsey/composer-install@v2
320+
with:
321+
working-directory: src/StimulusBundle
322+
dependency-versions: lowest
323+
- name: StimulusBundle Tests
324+
working-directory: src/StimulusBundle
325+
run: php vendor/bin/simple-phpunit
326+
327+
- name: Svelte Dependencies
328+
uses: ramsey/composer-install@v2
329+
with:
330+
working-directory: src/Svelte
331+
dependency-versions: lowest
332+
- name: Svelte Tests
333+
run: php vendor/bin/simple-phpunit
334+
working-directory: src/Svelte
335+
336+
- name: Vue Dependencies
337+
uses: ramsey/composer-install@v2
338+
with:
339+
working-directory: src/Vue
340+
dependency-versions: lowest
341+
- name: Vue Tests
342+
run: php vendor/bin/simple-phpunit
343+
working-directory: src/Vue
344+
282345
tests-js:
283346
runs-on: ubuntu-latest
284347
steps:

src/Autocomplete/src/DependencyInjection/AutocompleteExtension.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function prepend(ContainerBuilder $container)
4848
]);
4949
}
5050

51-
if (interface_exists(AssetMapperInterface::class)) {
51+
if ($this->isAssetMapperAvailable($container)) {
5252
$container->prependExtensionConfig('framework', [
5353
'asset_mapper' => [
5454
'paths' => [
@@ -155,4 +155,19 @@ private function registerFormServices(ContainerBuilder $container): void
155155
new Reference('ux.autocomplete.entity_search_util'),
156156
]);
157157
}
158+
159+
private function isAssetMapperAvailable(ContainerBuilder $container): bool
160+
{
161+
if (!interface_exists(AssetMapperInterface::class)) {
162+
return false;
163+
}
164+
165+
// check that FrameworkBundle 6.3 or higher is installed
166+
$bundlesMetadata = $container->getParameter('kernel.bundles_metadata');
167+
if (!isset($bundlesMetadata['FrameworkBundle'])) {
168+
return false;
169+
}
170+
171+
return is_file($bundlesMetadata['FrameworkBundle']['path'].'/Resources/config/asset_mapper.php');
172+
}
158173
}

src/Chartjs/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
"symfony/config": "^5.4|^6.0",
3333
"symfony/dependency-injection": "^5.4|^6.0",
3434
"symfony/http-kernel": "^5.4|^6.0",
35-
"symfony/stimulus-bundle": "^2.9"
35+
"symfony/stimulus-bundle": "^2.9.1"
3636
},
3737
"require-dev": {
3838
"symfony/framework-bundle": "^5.4|^6.0",

src/Chartjs/src/DependencyInjection/ChartjsExtension.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public function load(array $configs, ContainerBuilder $container)
5050

5151
public function prepend(ContainerBuilder $container)
5252
{
53-
if (!interface_exists(AssetMapperInterface::class)) {
53+
if (!$this->isAssetMapperAvailable($container)) {
5454
return;
5555
}
5656

@@ -62,4 +62,19 @@ public function prepend(ContainerBuilder $container)
6262
],
6363
]);
6464
}
65+
66+
private function isAssetMapperAvailable(ContainerBuilder $container): bool
67+
{
68+
if (!interface_exists(AssetMapperInterface::class)) {
69+
return false;
70+
}
71+
72+
// check that FrameworkBundle 6.3 or higher is installed
73+
$bundlesMetadata = $container->getParameter('kernel.bundles_metadata');
74+
if (!isset($bundlesMetadata['FrameworkBundle'])) {
75+
return false;
76+
}
77+
78+
return is_file($bundlesMetadata['FrameworkBundle']['path'].'/Resources/config/asset_mapper.php');
79+
}
6580
}

src/Cropperjs/src/DependencyInjection/CropperjsExtension.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function load(array $configs, ContainerBuilder $container)
5353

5454
public function prepend(ContainerBuilder $container)
5555
{
56-
if (!interface_exists(AssetMapperInterface::class)) {
56+
if (!$this->isAssetMapperAvailable($container)) {
5757
return;
5858
}
5959

@@ -65,4 +65,19 @@ public function prepend(ContainerBuilder $container)
6565
],
6666
]);
6767
}
68+
69+
private function isAssetMapperAvailable(ContainerBuilder $container): bool
70+
{
71+
if (!interface_exists(AssetMapperInterface::class)) {
72+
return false;
73+
}
74+
75+
// check that FrameworkBundle 6.3 or higher is installed
76+
$bundlesMetadata = $container->getParameter('kernel.bundles_metadata');
77+
if (!isset($bundlesMetadata['FrameworkBundle'])) {
78+
return false;
79+
}
80+
81+
return is_file($bundlesMetadata['FrameworkBundle']['path'].'/Resources/config/asset_mapper.php');
82+
}
6883
}

src/Dropzone/src/DependencyInjection/DropzoneExtension.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function prepend(ContainerBuilder $container)
3434
$container->prependExtensionConfig('twig', ['form_themes' => ['@Dropzone/form_theme.html.twig']]);
3535
}
3636

37-
if (interface_exists(AssetMapperInterface::class)) {
37+
if ($this->isAssetMapperAvailable($container)) {
3838
$container->prependExtensionConfig('framework', [
3939
'asset_mapper' => [
4040
'paths' => [
@@ -53,4 +53,19 @@ public function load(array $configs, ContainerBuilder $container)
5353
->setPublic(false)
5454
;
5555
}
56+
57+
private function isAssetMapperAvailable(ContainerBuilder $container): bool
58+
{
59+
if (!interface_exists(AssetMapperInterface::class)) {
60+
return false;
61+
}
62+
63+
// check that FrameworkBundle 6.3 or higher is installed
64+
$bundlesMetadata = $container->getParameter('kernel.bundles_metadata');
65+
if (!isset($bundlesMetadata['FrameworkBundle'])) {
66+
return false;
67+
}
68+
69+
return is_file($bundlesMetadata['FrameworkBundle']['path'].'/Resources/config/asset_mapper.php');
70+
}
5671
}

src/LazyImage/src/DependencyInjection/LazyImageExtension.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function load(array $configs, ContainerBuilder $container)
5757

5858
public function prepend(ContainerBuilder $container)
5959
{
60-
if (!interface_exists(AssetMapperInterface::class)) {
60+
if (!$this->isAssetMapperAvailable($container)) {
6161
return;
6262
}
6363

@@ -69,4 +69,19 @@ public function prepend(ContainerBuilder $container)
6969
],
7070
]);
7171
}
72+
73+
private function isAssetMapperAvailable(ContainerBuilder $container): bool
74+
{
75+
if (!interface_exists(AssetMapperInterface::class)) {
76+
return false;
77+
}
78+
79+
// check that FrameworkBundle 6.3 or higher is installed
80+
$bundlesMetadata = $container->getParameter('kernel.bundles_metadata');
81+
if (!isset($bundlesMetadata['FrameworkBundle'])) {
82+
return false;
83+
}
84+
85+
return is_file($bundlesMetadata['FrameworkBundle']['path'].'/Resources/config/asset_mapper.php');
86+
}
7287
}

src/LiveComponent/src/DependencyInjection/LiveComponentExtension.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public function prepend(ContainerBuilder $container)
6464
$container->prependExtensionConfig('twig', ['form_themes' => ['@LiveComponent/form_theme.html.twig']]);
6565
}
6666

67-
if (interface_exists(AssetMapperInterface::class)) {
67+
if ($this->isAssetMapperAvailable($container)) {
6868
$container->prependExtensionConfig('framework', [
6969
'asset_mapper' => [
7070
'paths' => [
@@ -213,4 +213,19 @@ function (ChildDefinition $definition, AsLiveComponent $attribute) {
213213
->setPublic(false)
214214
;
215215
}
216+
217+
private function isAssetMapperAvailable(ContainerBuilder $container): bool
218+
{
219+
if (!interface_exists(AssetMapperInterface::class)) {
220+
return false;
221+
}
222+
223+
// check that FrameworkBundle 6.3 or higher is installed
224+
$bundlesMetadata = $container->getParameter('kernel.bundles_metadata');
225+
if (!isset($bundlesMetadata['FrameworkBundle'])) {
226+
return false;
227+
}
228+
229+
return is_file($bundlesMetadata['FrameworkBundle']['path'].'/Resources/config/asset_mapper.php');
230+
}
216231
}

src/Notify/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"symfony/http-kernel": "^5.4|^6.0",
3535
"symfony/mercure-bundle": "^0.3.4",
3636
"symfony/mercure-notifier": "^5.4|^6.0",
37-
"symfony/stimulus-bundle": "^2.9",
37+
"symfony/stimulus-bundle": "^2.9.1",
3838
"symfony/twig-bundle": "^5.4|^6.0"
3939
},
4040
"require-dev": {

src/Notify/src/DependencyInjection/NotifyExtension.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function loadInternal(array $config, ContainerBuilder $container)
4343

4444
public function prepend(ContainerBuilder $container)
4545
{
46-
if (!interface_exists(AssetMapperInterface::class)) {
46+
if (!$this->isAssetMapperAvailable($container)) {
4747
return;
4848
}
4949

@@ -55,4 +55,19 @@ public function prepend(ContainerBuilder $container)
5555
],
5656
]);
5757
}
58+
59+
private function isAssetMapperAvailable(ContainerBuilder $container): bool
60+
{
61+
if (!interface_exists(AssetMapperInterface::class)) {
62+
return false;
63+
}
64+
65+
// check that FrameworkBundle 6.3 or higher is installed
66+
$bundlesMetadata = $container->getParameter('kernel.bundles_metadata');
67+
if (!isset($bundlesMetadata['FrameworkBundle'])) {
68+
return false;
69+
}
70+
71+
return is_file($bundlesMetadata['FrameworkBundle']['path'].'/Resources/config/asset_mapper.php');
72+
}
5873
}

0 commit comments

Comments
 (0)