Skip to content

Commit d385cf7

Browse files
devclaude
andcommitted
feat: add S3 resolver path_style, credentials config + relativePath in Twig macros
Add path_style and credentials options to S3ResolverFactory for LocalStack/MinIO compatibility. Update Twig image macros to prefer relativePath over uri for correct image filter resolution with S3. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 776cdf2 commit d385cf7

2 files changed

Lines changed: 32 additions & 8 deletions

File tree

src/DependencyInjection/Factory/Resolver/S3ResolverFactory.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,19 @@ public function create(ContainerBuilder $container, string $name, array $config)
3838
$clientArgs['endpoint'] = $config['endpoint'];
3939
}
4040

41+
if ($config['path_style'] ?? false) {
42+
$clientArgs['use_path_style_endpoint'] = true;
43+
}
44+
45+
if (isset($config['credentials'])) {
46+
/** @var array{key: string, secret: string} $credentials */
47+
$credentials = $config['credentials'];
48+
$clientArgs['credentials'] = [
49+
'key' => $credentials['key'],
50+
'secret' => $credentials['secret'],
51+
];
52+
}
53+
4154
$clientDefinition = new Definition(S3Client::class, [$clientArgs]);
4255
$clientId = \sprintf('chamber_orchestra_image.cache.resolver.%s.client', $name);
4356
$container->setDefinition($clientId, $clientDefinition);
@@ -92,6 +105,17 @@ public function addConfiguration(ArrayNodeDefinition $builder): void
92105
->defaultNull()
93106
->info('ACL for stored objects (e.g. "public-read"). Null to omit.')
94107
->end()
108+
->booleanNode('path_style')
109+
->defaultFalse()
110+
->info('Use path-style addressing (required for LocalStack/MinIO).')
111+
->end()
112+
->arrayNode('credentials')
113+
->children()
114+
->scalarNode('key')->isRequired()->end()
115+
->scalarNode('secret')->isRequired()->end()
116+
->end()
117+
->info('Explicit AWS credentials. Omit to use default credential chain.')
118+
->end()
95119
->end()
96120
;
97121
}

src/Resources/views/macro/image.html.twig

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
{%- endmacro -%}
1414

1515
{%- macro fit(src, width, height, attr, picture_attr = {}) -%}
16-
{# add support of ChamberOrchestra\FileBundle\Model\File #}
17-
{%- set src = src.uri|default(src) -%}
16+
{# add support of ChamberOrchestra\FileBundle\Model\File — use relativePath for image filters, falls back to uri #}
17+
{%- set src = src.relativePath|default(src.uri|default(src)) -%}
1818
{%- set attr = attr|default({})|merge({width: attr.width|default(width), height: attr.height|default(height), style: 'height: auto', loading: 'lazy', decoding: 'async'}) -%}
1919
<picture {{ _self.attributes(picture_attr) -}}>
2020
<source {#
@@ -36,8 +36,8 @@
3636
{%- endmacro -%}
3737

3838
{%- macro fill(src, width, height, attr, picture_attr = {}) -%}
39-
{# add support of ChamberOrchestra\FileBundle\Model\File #}
40-
{%- set src = src.uri|default(src) -%}
39+
{# add support of ChamberOrchestra\FileBundle\Model\File — use relativePath for image filters, falls back to uri #}
40+
{%- set src = src.relativePath|default(src.uri|default(src)) -%}
4141
{%- set attr = attr|default({})|merge({width: attr.width|default(width), height: attr.height|default(height), style: 'height: auto', loading: 'lazy', decoding: 'async'}) -%}
4242

4343
<picture {{ _self.attributes(picture_attr) -}}>
@@ -61,8 +61,8 @@
6161

6262
{%- macro css_fit(src, width, height, use2x = true) -%}
6363

64-
{# add support of ChamberOrchestra\FileBundle\Model\File #}
65-
{%- set src = src.uri|default(src) -%}
64+
{# add support of ChamberOrchestra\FileBundle\Model\File — use relativePath for image filters, falls back to uri #}
65+
{%- set src = src.relativePath|default(src.uri|default(src)) -%}
6666
{%- set url = (src|default('')|fit(width, height)) -%}
6767
{%- set webp = (src|default('')|fit(width, height, {output: {format: 'webp'}})) -%}
6868
{%- set avif = (src|default('')|fit(width, height, {output: {format: 'avif'}})) -%}
@@ -104,8 +104,8 @@
104104

105105
{%- macro css_fill(src, width, height, use2x = true) -%}
106106

107-
{# add support of ChamberOrchestra\FileBundle\Model\File #}
108-
{%- set src = src.uri|default(src) -%}
107+
{# add support of ChamberOrchestra\FileBundle\Model\File — use relativePath for image filters, falls back to uri #}
108+
{%- set src = src.relativePath|default(src.uri|default(src)) -%}
109109

110110
{%- set url = (src|default('')|fill(width, height)) -%}
111111
{%- set webp = (src|default('')|fill(width, height, {output: {format: 'webp'}})) -%}

0 commit comments

Comments
 (0)