Skip to content

Commit a0d09f4

Browse files
authored
Merge pull request #649 from FriendsOfSymfony/2-to-3
merge 2.x to 3.x
2 parents 83f269f + f117fe9 commit a0d09f4

File tree

12 files changed

+121
-3
lines changed

12 files changed

+121
-3
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +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` and `stream_factory` to support custom PSR-17 HTTP request and stream factories for proxy clients.
1213

1314
3.1.2
1415
-----
@@ -53,6 +54,11 @@ Changelog
5354
2.x
5455
===
5556

57+
2.18.0
58+
------
59+
60+
* New configuration option `proxy_client.*.http.request_factory` to support custom HTTP request factories for proxy clients.
61+
5662
2.17.1
5763
------
5864

Resources/doc/features/invalidation.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ To refresh paths and routes, you can use ``refreshPath($path, $headers)`` and
6666

6767
If you want to add a header (such as ``Authorization``) to *all*
6868
invalidation requests, you can use a
69-
:ref:`custom HTTP client <custom HTTP client>` instead.
69+
:ref:`custom HTTP client <custom HTTP client>` or
70+
:ref:`custom HTTP request factory <custom HTTP request factory>` instead.
7071

7172
.. _invalidation configuration:
7273

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,23 @@ example to send a basic authentication header with each request, you can
400400
configure a service for the ``HttpClient`` and specify that in the
401401
``http_client`` option of any of the cache proxy clients.
402402

403+
.. _custom HTTP request factory:
404+
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.
415+
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.
419+
403420
Caching Proxy Configuration
404421
---------------------------
405422

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: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,14 @@ private function getHttpDispatcherNode(): ArrayNodeDefinition
624624
->defaultNull()
625625
->info('Httplug async client service name to use for sending the requests.')
626626
->end()
627+
->scalarNode('request_factory')
628+
->defaultNull()
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.')
634+
->end()
627635
->end()
628636
;
629637

src/DependencyInjection/FOSHttpCacheExtension.php

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,18 @@ private function loadVarnish(ContainerBuilder $container, XmlFileLoader $loader,
427427
$container->setParameter('fos_http_cache.proxy_client.varnish.options', $options);
428428

429429
$loader->load('varnish.xml');
430+
431+
$requestFactory = isset($config['http']['request_factory'])
432+
? new Reference($config['http']['request_factory'])
433+
: null;
434+
$container->getDefinition('fos_http_cache.proxy_client.varnish')
435+
->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);
430442
}
431443

432444
private function loadNginx(ContainerBuilder $container, XmlFileLoader $loader, array $config): void
@@ -436,6 +448,18 @@ private function loadNginx(ContainerBuilder $container, XmlFileLoader $loader, a
436448
'purge_location' => $config['purge_location'],
437449
]);
438450
$loader->load('nginx.xml');
451+
452+
$requestFactory = isset($config['http']['request_factory'])
453+
? new Reference($config['http']['request_factory'])
454+
: null;
455+
$container->getDefinition('fos_http_cache.proxy_client.nginx')
456+
->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);
439463
}
440464

441465
private function loadSymfony(ContainerBuilder $container, XmlFileLoader $loader, array $config): void
@@ -462,6 +486,18 @@ private function loadSymfony(ContainerBuilder $container, XmlFileLoader $loader,
462486
$container->setParameter('fos_http_cache.proxy_client.symfony.options', $options);
463487

464488
$loader->load('symfony.xml');
489+
490+
$requestFactory = isset($config['http']['request_factory'])
491+
? new Reference($config['http']['request_factory'])
492+
: null;
493+
$container->getDefinition('fos_http_cache.proxy_client.symfony')
494+
->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);
465501
}
466502

467503
private function loadCloudflare(ContainerBuilder $container, XmlFileLoader $loader, array $config): void
@@ -475,6 +511,18 @@ private function loadCloudflare(ContainerBuilder $container, XmlFileLoader $load
475511
$container->setParameter('fos_http_cache.proxy_client.cloudflare.options', $options);
476512

477513
$loader->load('cloudflare.xml');
514+
515+
$requestFactory = isset($config['http']['request_factory'])
516+
? new Reference($config['http']['request_factory'])
517+
: null;
518+
$container->getDefinition('fos_http_cache.proxy_client.cloudflare')
519+
->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);
478526
}
479527

480528
private function loadCloudfront(ContainerBuilder $container, XmlFileLoader $loader, array $config): void
@@ -511,6 +559,18 @@ private function loadFastly(ContainerBuilder $container, XmlFileLoader $loader,
511559
$container->setParameter('fos_http_cache.proxy_client.fastly.options', $options);
512560

513561
$loader->load('fastly.xml');
562+
563+
$requestFactory = isset($config['http']['request_factory'])
564+
? new Reference($config['http']['request_factory'])
565+
: null;
566+
$container->getDefinition('fos_http_cache.proxy_client.fastly')
567+
->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);
514574
}
515575

516576
/**

src/Resources/config/cloudflare.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
lazy="true">
1212
<argument type="service" id="fos_http_cache.proxy_client.cloudflare.http_dispatcher"/>
1313
<argument>%fos_http_cache.proxy_client.cloudflare.options%</argument>
14+
<argument /> <!-- request factory -->
15+
<argument /> <!-- stream factory -->
1416
</service>
1517
</services>
1618

src/Resources/config/fastly.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
lazy="true">
1212
<argument type="service" id="fos_http_cache.proxy_client.fastly.http_dispatcher"/>
1313
<argument>%fos_http_cache.proxy_client.fastly.options%</argument>
14+
<argument /> <!-- request factory -->
15+
<argument /> <!-- stream factory -->
1416
</service>
1517
</services>
1618

src/Resources/config/nginx.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
public="true">
1111
<argument type="service" id="fos_http_cache.proxy_client.nginx.http_dispatcher"/>
1212
<argument>%fos_http_cache.proxy_client.nginx.options%</argument>
13+
<argument /> <!-- request factory -->
14+
<argument /> <!-- stream factory -->
1315
</service>
1416
</services>
1517

src/Resources/config/symfony.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
public="true">
1111
<argument type="service" id="fos_http_cache.proxy_client.symfony.http_dispatcher"/>
1212
<argument>%fos_http_cache.proxy_client.symfony.options%</argument>
13+
<argument /> <!-- request factory -->
14+
<argument /> <!-- stream factory -->
1315
</service>
1416
</services>
1517

0 commit comments

Comments
 (0)