-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: static typing and final classes (#621)
* fix: static typing and final classes * remove legacy code in Configuration class
- Loading branch information
Showing
26 changed files
with
73 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,6 @@ | |
use JeanBeru\HttpCacheCloudFront\Proxy\CloudFront; | ||
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; | ||
use Symfony\Component\Config\Definition\Builder\NodeBuilder; | ||
use Symfony\Component\Config\Definition\Builder\NodeDefinition; | ||
use Symfony\Component\Config\Definition\Builder\TreeBuilder; | ||
use Symfony\Component\Config\Definition\ConfigurationInterface; | ||
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException; | ||
|
@@ -34,7 +33,7 @@ | |
* @author David de Boer <[email protected]> | ||
* @author David Buchmann <[email protected]> | ||
*/ | ||
class Configuration implements ConfigurationInterface | ||
final class Configuration implements ConfigurationInterface | ||
{ | ||
/** | ||
* @var bool | ||
|
@@ -55,13 +54,7 @@ public function __construct($debug) | |
public function getConfigTreeBuilder(): TreeBuilder | ||
{ | ||
$treeBuilder = new TreeBuilder('fos_http_cache'); | ||
|
||
// Keep compatibility with symfony/config < 4.2 | ||
if (!method_exists($treeBuilder, 'getRootNode')) { | ||
$rootNode = $treeBuilder->root('fos_http_cache'); | ||
} else { | ||
$rootNode = $treeBuilder->getRootNode(); | ||
} | ||
$rootNode = $treeBuilder->getRootNode(); | ||
|
||
$rootNode | ||
->validate() | ||
|
@@ -240,7 +233,7 @@ private function isFastly(array $v): bool | |
&& array_key_exists('fastly', $v['proxy_client']); | ||
} | ||
|
||
private function addCacheableResponseSection(ArrayNodeDefinition $rootNode) | ||
private function addCacheableResponseSection(ArrayNodeDefinition $rootNode): void | ||
{ | ||
$rootNode | ||
->children() | ||
|
@@ -278,7 +271,7 @@ private function addCacheableResponseSection(ArrayNodeDefinition $rootNode) | |
/** | ||
* Cache header control main section. | ||
*/ | ||
private function addCacheControlSection(ArrayNodeDefinition $rootNode) | ||
private function addCacheControlSection(ArrayNodeDefinition $rootNode): void | ||
{ | ||
$rules = $rootNode | ||
->children() | ||
|
@@ -366,7 +359,7 @@ private function addCacheControlSection(ArrayNodeDefinition $rootNode) | |
* | ||
* @param bool $matchResponse whether to also add fields to match response | ||
*/ | ||
private function addMatch(NodeBuilder $rules, $matchResponse = false) | ||
private function addMatch(NodeBuilder $rules, $matchResponse = false): void | ||
{ | ||
$match = $rules | ||
->arrayNode('match') | ||
|
@@ -610,19 +603,11 @@ private function addProxyClientSection(ArrayNodeDefinition $rootNode): void | |
|
||
/** | ||
* Get the configuration node for a HTTP dispatcher in a proxy client. | ||
* | ||
* @return NodeDefinition | ||
*/ | ||
private function getHttpDispatcherNode() | ||
private function getHttpDispatcherNode(): ArrayNodeDefinition | ||
{ | ||
$treeBuilder = new TreeBuilder('http'); | ||
|
||
// Keep compatibility with symfony/config < 4.2 | ||
if (!method_exists($treeBuilder, 'getRootNode')) { | ||
$node = $treeBuilder->root('http'); | ||
} else { | ||
$node = $treeBuilder->getRootNode(); | ||
} | ||
$node = $treeBuilder->getRootNode(); | ||
|
||
$node | ||
->fixXmlConfig('server') | ||
|
@@ -650,16 +635,10 @@ private function getHttpDispatcherNode() | |
return $node; | ||
} | ||
|
||
private function getCloudflareHttpDispatcherNode() | ||
private function getCloudflareHttpDispatcherNode(): ArrayNodeDefinition | ||
{ | ||
$treeBuilder = new TreeBuilder('http'); | ||
|
||
// Keep compatibility with symfony/config < 4.2 | ||
if (!method_exists($treeBuilder, 'getRootNode')) { | ||
$node = $treeBuilder->root('http'); | ||
} else { | ||
$node = $treeBuilder->getRootNode(); | ||
} | ||
$node = $treeBuilder->getRootNode(); | ||
|
||
$node | ||
->addDefaultsIfNotSet() | ||
|
@@ -680,10 +659,9 @@ private function getCloudflareHttpDispatcherNode() | |
return $node; | ||
} | ||
|
||
private function getFastlyHttpDispatcherNode() | ||
private function getFastlyHttpDispatcherNode(): ArrayNodeDefinition | ||
{ | ||
$treeBuilder = new TreeBuilder('http'); | ||
|
||
$node = $treeBuilder->getRootNode(); | ||
|
||
$node | ||
|
@@ -709,7 +687,7 @@ private function getFastlyHttpDispatcherNode() | |
return $node; | ||
} | ||
|
||
private function addTestSection(ArrayNodeDefinition $rootNode) | ||
private function addTestSection(ArrayNodeDefinition $rootNode): void | ||
{ | ||
$rootNode | ||
->children() | ||
|
@@ -752,7 +730,7 @@ private function addTestSection(ArrayNodeDefinition $rootNode) | |
/** | ||
* Cache manager main section. | ||
*/ | ||
private function addCacheManagerSection(ArrayNodeDefinition $rootNode) | ||
private function addCacheManagerSection(ArrayNodeDefinition $rootNode): void | ||
{ | ||
$rootNode | ||
->children() | ||
|
@@ -792,7 +770,7 @@ private function addCacheManagerSection(ArrayNodeDefinition $rootNode) | |
; | ||
} | ||
|
||
private function addTagSection(ArrayNodeDefinition $rootNode) | ||
private function addTagSection(ArrayNodeDefinition $rootNode): void | ||
{ | ||
$rules = $rootNode | ||
->children() | ||
|
@@ -848,7 +826,7 @@ private function addTagSection(ArrayNodeDefinition $rootNode) | |
; | ||
} | ||
|
||
private function addInvalidationSection(ArrayNodeDefinition $rootNode) | ||
private function addInvalidationSection(ArrayNodeDefinition $rootNode): void | ||
{ | ||
$rules = $rootNode | ||
->children() | ||
|
@@ -889,7 +867,7 @@ private function addInvalidationSection(ArrayNodeDefinition $rootNode) | |
/** | ||
* User context main section. | ||
*/ | ||
private function addUserContextListenerSection(ArrayNodeDefinition $rootNode) | ||
private function addUserContextListenerSection(ArrayNodeDefinition $rootNode): void | ||
{ | ||
$rootNode | ||
->children() | ||
|
@@ -958,7 +936,7 @@ private function addUserContextListenerSection(ArrayNodeDefinition $rootNode) | |
; | ||
} | ||
|
||
private function addFlashMessageSection(ArrayNodeDefinition $rootNode) | ||
private function addFlashMessageSection(ArrayNodeDefinition $rootNode): void | ||
{ | ||
$rootNode | ||
->children() | ||
|
@@ -988,7 +966,7 @@ private function addFlashMessageSection(ArrayNodeDefinition $rootNode) | |
->end(); | ||
} | ||
|
||
private function addDebugSection(ArrayNodeDefinition $rootNode) | ||
private function addDebugSection(ArrayNodeDefinition $rootNode): void | ||
{ | ||
$rootNode | ||
->children() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,7 @@ | |
* | ||
* @author Yoann Chocteau <[email protected]> | ||
*/ | ||
class AttributesListener implements EventSubscriberInterface | ||
final class AttributesListener implements EventSubscriberInterface | ||
{ | ||
public function __construct( | ||
private ControllerResolverInterface $controllerResolver | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,7 +26,7 @@ | |
* @author Lea Haensenberger <[email protected]> | ||
* @author David Buchmann <[email protected]> | ||
*/ | ||
class CacheControlListener implements EventSubscriberInterface | ||
final class CacheControlListener implements EventSubscriberInterface | ||
{ | ||
/** | ||
* Whether to skip this response and not set any cache headers. | ||
|
@@ -52,7 +52,7 @@ class CacheControlListener implements EventSubscriberInterface | |
* If not empty, add a debug header with that name to all responses, | ||
* telling the cache proxy to add debug output. | ||
* | ||
* @var string|bool Name of the header or false to add no header | ||
* @var string|false Name of the header or false to add no header | ||
*/ | ||
private string|false $debugHeader; | ||
|
||
|
@@ -96,7 +96,7 @@ public function onKernelResponse(ResponseEvent $event): void | |
$response = $event->getResponse(); | ||
|
||
if ($this->debugHeader) { | ||
$response->headers->set($this->debugHeader, 1, false); | ||
$response->headers->set($this->debugHeader, '1', false); | ||
} | ||
|
||
// do not change cache directives on non-cacheable requests. | ||
|
@@ -125,7 +125,7 @@ public function onKernelResponse(ResponseEvent $event): void | |
&& null !== $options['reverse_proxy_ttl'] | ||
&& !$response->headers->has('X-Reverse-Proxy-TTL') | ||
) { | ||
$response->headers->set('X-Reverse-Proxy-TTL', (int) $options['reverse_proxy_ttl'], false); | ||
$response->headers->set('X-Reverse-Proxy-TTL', $options['reverse_proxy_ttl'], false); | ||
} | ||
|
||
if (!empty($options['vary'])) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,7 +33,7 @@ | |
* | ||
* @author David de Boer <[email protected]> | ||
*/ | ||
class InvalidationListener extends AbstractRuleListener implements EventSubscriberInterface | ||
final class InvalidationListener extends AbstractRuleListener implements EventSubscriberInterface | ||
{ | ||
private CacheManager $cacheManager; | ||
private UrlGeneratorInterface $urlGenerator; | ||
|
@@ -136,7 +136,7 @@ private function handleInvalidation(Request $request, Response $response): void | |
} | ||
|
||
// Check configured invalidators | ||
if (!$invalidatorConfigs = $this->matchRule($request, $response)) { | ||
if (!$invalidatorConfigs = $this->matchRule($request)) { | ||
return; | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,7 +27,7 @@ | |
* | ||
* @author David de Boer <[email protected]> | ||
*/ | ||
class TagListener extends AbstractRuleListener implements EventSubscriberInterface | ||
final class TagListener extends AbstractRuleListener implements EventSubscriberInterface | ||
{ | ||
private CacheManager $cacheManager; | ||
private SymfonyResponseTagger $symfonyResponseTagger; | ||
|
@@ -108,7 +108,7 @@ public static function getSubscribedEvents(): array | |
* Get the tags from the attributes on the controller that was used in the | ||
* request. | ||
* | ||
* @return array List of tags affected by the request | ||
* @return string[] List of tags affected by the request | ||
*/ | ||
private function getAttributeTags(Request $request): array | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,7 +34,7 @@ | |
* @author Stefan Paschke <[email protected]> | ||
* @author Joel Wurtz <[email protected]> | ||
*/ | ||
class UserContextListener implements EventSubscriberInterface | ||
final class UserContextListener implements EventSubscriberInterface | ||
{ | ||
private RequestMatcherInterface $requestMatcher; | ||
private HashGenerator $hashGenerator; | ||
|
@@ -136,7 +136,7 @@ public function onKernelRequest(RequestEvent $event): void | |
$response->setPublic(); | ||
if ($this->hasSessionListener) { | ||
// header to avoid Symfony SessionListener overwriting the response to private | ||
$response->headers->set(AbstractSessionListener::NO_AUTO_CACHE_CONTROL_HEADER, 1); | ||
$response->headers->set(AbstractSessionListener::NO_AUTO_CACHE_CONTROL_HEADER, '1'); | ||
} | ||
} else { | ||
$response->setClientTtl(0); | ||
|
@@ -201,7 +201,7 @@ public function onKernelResponse(ResponseEvent $event): void | |
// user hash header was in vary or just added here by "add_vary_on_hash" | ||
if ($this->hasSessionListener && in_array($this->options['user_hash_header'], $vary, true)) { | ||
// header to avoid Symfony SessionListener overwriting the response to private | ||
$response->headers->set(AbstractSessionListener::NO_AUTO_CACHE_CONTROL_HEADER, 1); | ||
$response->headers->set(AbstractSessionListener::NO_AUTO_CACHE_CONTROL_HEADER, '1'); | ||
} | ||
} elseif ($this->options['add_vary_on_hash']) { | ||
/* | ||
|
Oops, something went wrong.