Skip to content

Commit

Permalink
Merge pull request #639 from richardhj/patch-1
Browse files Browse the repository at this point in the history
Fix php error
  • Loading branch information
dbu authored Jan 9, 2025
2 parents 7b737f7 + a13756b commit 0f593e4
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use FOS\HttpCache\SymfonyCache\PurgeListener;
use FOS\HttpCache\SymfonyCache\PurgeTagsListener;
use FOS\HttpCache\TagHeaderFormatter\TagHeaderFormatter;
use FOS\HttpCacheBundle\EventListener\CacheControlListener;
use JeanBeru\HttpCacheCloudFront\Proxy\CloudFront;
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Symfony\Component\Config\Definition\Builder\NodeBuilder;
Expand Down Expand Up @@ -278,7 +279,7 @@ private function addCacheControlSection(ArrayNodeDefinition $rootNode): void
->end()
->end()
->scalarNode('ttl_header')
->defaultValue('X-Reverse-Proxy-TTL')
->defaultValue(CacheControlListener::DEFAULT_TTL_HEADER_NAME)
->info('Specify the header name to use with the cache_control.reverse_proxy_ttl setting')
->end()
->arrayNode('rules')
Expand Down
3 changes: 2 additions & 1 deletion src/DependencyInjection/FOSHttpCacheExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use FOS\HttpCache\SymfonyCache\KernelDispatcher;
use FOS\HttpCache\TagHeaderFormatter\MaxHeaderValueLengthFormatter;
use FOS\HttpCacheBundle\DependencyInjection\Compiler\HashGeneratorPass;
use FOS\HttpCacheBundle\EventListener\CacheControlListener;
use FOS\HttpCacheBundle\Http\ResponseMatcher\ExpressionResponseMatcher;
use Symfony\Component\Config\Definition\ConfigurationInterface;
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
Expand Down Expand Up @@ -48,7 +49,7 @@ public function load(array $configs, ContainerBuilder $container): void

if ($config['debug']['enabled'] || (!empty($config['cache_control']))) {
$debugHeader = $config['debug']['enabled'] ? $config['debug']['header'] : false;
$ttlHeader = $config['cache_control']['ttl_header'];
$ttlHeader = $config['cache_control']['ttl_header'] ?? CacheControlListener::DEFAULT_TTL_HEADER_NAME;
$container->setParameter('fos_http_cache.debug_header', $debugHeader);
$container->setParameter('fos_http_cache.ttl_header', $ttlHeader);
$loader->load('cache_control_listener.xml');
Expand Down
4 changes: 3 additions & 1 deletion src/EventListener/CacheControlListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
*/
final class CacheControlListener implements EventSubscriberInterface
{
public const DEFAULT_TTL_HEADER_NAME = 'X-Reverse-Proxy-TTL';

/**
* Whether to skip this response and not set any cache headers.
*/
Expand Down Expand Up @@ -56,7 +58,7 @@ public function __construct(
* @var string|false Name of the header or false to add no header
*/
private readonly string|false $debugHeader = false,
private readonly string $ttlHeader = 'X-Reverse-Proxy-TTL',
private readonly string $ttlHeader = self::DEFAULT_TTL_HEADER_NAME,
) {
}

Expand Down

0 comments on commit 0f593e4

Please sign in to comment.