Skip to content

Commit f117fe9

Browse files
committed
add support to configure stream factory as well
1 parent c1b8644 commit f117fe9

File tree

11 files changed

+64
-9
lines changed

11 files changed

+64
-9
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Changelog
99

1010
* If a custom proxy client is configured on the cache manager, the `ProxyClient` class is an alias to that client, to support autowiring.
1111
* Attribute configuration now also works on single action controllers with the `__invoke` method.
12-
* New configuration option `proxy_client.*.http.request_factory` to support custom HTTP request factories for proxy clients.
12+
* New configuration option `proxy_client.*.http.request_factory` and `stream_factory` to support custom PSR-17 HTTP request and stream factories for proxy clients.
1313

1414
3.1.2
1515
-----

Resources/doc/reference/configuration/proxy-client.rst

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -402,12 +402,20 @@ configure a service for the ``HttpClient`` and specify that in the
402402

403403
.. _custom HTTP request factory:
404404

405-
Custom HTTP Request Factory
406-
---------------------------
405+
Custom HTTP Request Factory and Stream Factory
406+
----------------------------------------------
407+
408+
The proxy client uses an implementation of PSR-17 ``Psr\Http\Message\RequestFactoryInterface``
409+
to create HTTP requests and ``Psr\Http\Message\StreamFactoryInterface`` to
410+
create streams.
411+
412+
If you need to customize request creation, you can configure your custom
413+
service and specify that in the ``request_factory`` option of any of the cache
414+
proxy clients.
407415

408-
The proxy client uses an implementation of ``Http\Message\RequestFactory`` to create HTTP requests.
409-
If you need to customize the request creation, you can configure your custom service and
410-
specify that in the ``request_factory`` option of any of the cache proxy clients.
416+
If you need to customize stream creation, you can configure your custom service
417+
and specify that in the ``stream_factory`` option of any of the cache proxy
418+
clients.
411419

412420
Caching Proxy Configuration
413421
---------------------------

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
],
3030
"require": {
3131
"php": "^8.1",
32-
"friendsofsymfony/http-cache": "^2.15 || ^3.0",
32+
"friendsofsymfony/http-cache": "^3.0",
3333
"symfony/dependency-injection": "^6.4 || ^7.0",
3434
"symfony/expression-language": "^6.4 || ^7.0",
3535
"symfony/framework-bundle": "^6.4 || ^7.0",
@@ -60,7 +60,7 @@
6060
"phpstan/phpstan": "^2",
6161
"phpstan/phpstan-symfony": "^2",
6262
"phpstan/extension-installer": "^1.4",
63-
"jean-beru/fos-http-cache-cloudfront": "^1.1",
63+
"jean-beru/fos-http-cache-cloudfront": "^1.1.1",
6464
"friendsofphp/php-cs-fixer": "^3.54"
6565
},
6666
"suggest": {

src/DependencyInjection/Configuration.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,11 @@ private function getHttpDispatcherNode(): ArrayNodeDefinition
626626
->end()
627627
->scalarNode('request_factory')
628628
->defaultNull()
629-
->info('Service name of PSR-17 factory for HTTP messages.')
629+
->info('Service name of PSR-17 message factory.')
630+
->end()
631+
->scalarNode('stream_factory')
632+
->defaultNull()
633+
->info('Service name of PSR-17 stream factory.')
630634
->end()
631635
->end()
632636
;

src/DependencyInjection/FOSHttpCacheExtension.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,12 @@ private function loadVarnish(ContainerBuilder $container, XmlFileLoader $loader,
433433
: null;
434434
$container->getDefinition('fos_http_cache.proxy_client.varnish')
435435
->replaceArgument(2, $requestFactory);
436+
437+
$streamFactory = isset($config['http']['stream_factory'])
438+
? new Reference($config['http']['stream_factory'])
439+
: null;
440+
$container->getDefinition('fos_http_cache.proxy_client.varnish')
441+
->replaceArgument(3, $streamFactory);
436442
}
437443

438444
private function loadNginx(ContainerBuilder $container, XmlFileLoader $loader, array $config): void
@@ -448,6 +454,12 @@ private function loadNginx(ContainerBuilder $container, XmlFileLoader $loader, a
448454
: null;
449455
$container->getDefinition('fos_http_cache.proxy_client.nginx')
450456
->replaceArgument(2, $requestFactory);
457+
458+
$streamFactory = isset($config['http']['stream_factory'])
459+
? new Reference($config['http']['stream_factory'])
460+
: null;
461+
$container->getDefinition('fos_http_cache.proxy_client.nginx')
462+
->replaceArgument(3, $streamFactory);
451463
}
452464

453465
private function loadSymfony(ContainerBuilder $container, XmlFileLoader $loader, array $config): void
@@ -480,6 +492,12 @@ private function loadSymfony(ContainerBuilder $container, XmlFileLoader $loader,
480492
: null;
481493
$container->getDefinition('fos_http_cache.proxy_client.symfony')
482494
->replaceArgument(2, $requestFactory);
495+
496+
$streamFactory = isset($config['http']['stream_factory'])
497+
? new Reference($config['http']['stream_factory'])
498+
: null;
499+
$container->getDefinition('fos_http_cache.proxy_client.symfony')
500+
->replaceArgument(3, $streamFactory);
483501
}
484502

485503
private function loadCloudflare(ContainerBuilder $container, XmlFileLoader $loader, array $config): void
@@ -499,6 +517,12 @@ private function loadCloudflare(ContainerBuilder $container, XmlFileLoader $load
499517
: null;
500518
$container->getDefinition('fos_http_cache.proxy_client.cloudflare')
501519
->replaceArgument(2, $requestFactory);
520+
521+
$streamFactory = isset($config['http']['stream_factory'])
522+
? new Reference($config['http']['stream_factory'])
523+
: null;
524+
$container->getDefinition('fos_http_cache.proxy_client.cloudflare')
525+
->replaceArgument(3, $streamFactory);
502526
}
503527

504528
private function loadCloudfront(ContainerBuilder $container, XmlFileLoader $loader, array $config): void
@@ -541,6 +565,12 @@ private function loadFastly(ContainerBuilder $container, XmlFileLoader $loader,
541565
: null;
542566
$container->getDefinition('fos_http_cache.proxy_client.fastly')
543567
->replaceArgument(2, $requestFactory);
568+
569+
$streamFactory = isset($config['http']['stream_factory'])
570+
? new Reference($config['http']['stream_factory'])
571+
: null;
572+
$container->getDefinition('fos_http_cache.proxy_client.fastly')
573+
->replaceArgument(3, $streamFactory);
544574
}
545575

546576
/**

src/Resources/config/cloudflare.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
<argument type="service" id="fos_http_cache.proxy_client.cloudflare.http_dispatcher"/>
1313
<argument>%fos_http_cache.proxy_client.cloudflare.options%</argument>
1414
<argument /> <!-- request factory -->
15+
<argument /> <!-- stream factory -->
1516
</service>
1617
</services>
1718

src/Resources/config/fastly.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
<argument type="service" id="fos_http_cache.proxy_client.fastly.http_dispatcher"/>
1313
<argument>%fos_http_cache.proxy_client.fastly.options%</argument>
1414
<argument /> <!-- request factory -->
15+
<argument /> <!-- stream factory -->
1516
</service>
1617
</services>
1718

src/Resources/config/nginx.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
<argument type="service" id="fos_http_cache.proxy_client.nginx.http_dispatcher"/>
1212
<argument>%fos_http_cache.proxy_client.nginx.options%</argument>
1313
<argument /> <!-- request factory -->
14+
<argument /> <!-- stream factory -->
1415
</service>
1516
</services>
1617

src/Resources/config/symfony.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
<argument type="service" id="fos_http_cache.proxy_client.symfony.http_dispatcher"/>
1212
<argument>%fos_http_cache.proxy_client.symfony.options%</argument>
1313
<argument /> <!-- request factory -->
14+
<argument /> <!-- stream factory -->
1415
</service>
1516
</services>
1617

src/Resources/config/varnish.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
<argument type="service" id="fos_http_cache.proxy_client.varnish.http_dispatcher"/>
1212
<argument>%fos_http_cache.proxy_client.varnish.options%</argument>
1313
<argument /> <!-- request factory -->
14+
<argument /> <!-- stream factory -->
1415
</service>
1516
</services>
1617

0 commit comments

Comments
 (0)