Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions src/CacheInvalidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,11 @@ class CacheInvalidator
*/
public const CLEAR = 'clear';

private ProxyClient $cache;

private EventDispatcherInterface $eventDispatcher;

public function __construct(ProxyClient $cache)
{
$this->cache = $cache;
public function __construct(
private readonly ProxyClient $cache,
) {
}

/**
Expand Down
8 changes: 3 additions & 5 deletions src/EventListener/LogListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,9 @@
*/
class LogListener implements EventSubscriberInterface
{
private LoggerInterface $logger;

public function __construct(LoggerInterface $logger)
{
$this->logger = $logger;
public function __construct(
private readonly LoggerInterface $logger,
) {
}

public static function getSubscribedEvents(): array
Expand Down
10 changes: 2 additions & 8 deletions src/ProxyClient/HttpProxyClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,6 @@
*/
abstract class HttpProxyClient implements ProxyClient
{
/**
* Dispatcher for invalidation HTTP requests.
*/
private Dispatcher $httpDispatcher;

private RequestFactoryInterface $requestFactory;
private StreamFactoryInterface $streamFactory;

Expand All @@ -43,20 +38,19 @@ abstract class HttpProxyClient implements ProxyClient
/**
* The base class has no options.
*
* @param Dispatcher $dispatcher Helper to send instructions to the caching proxy
* @param Dispatcher $httpDispatcher Helper to send instructions to the caching proxy
* @param array $options Options for this client
* @param RequestFactoryInterface|null $requestFactory Factory for PSR-7 messages. If none supplied,
* a default one is created
* @param StreamFactoryInterface|null $streamFactory Factory for PSR-7 streams. If none supplied,
* a default one is created
*/
public function __construct(
Dispatcher $dispatcher,
private readonly Dispatcher $httpDispatcher,
array $options = [],
?RequestFactoryInterface $requestFactory = null,
?StreamFactoryInterface $streamFactory = null,
) {
$this->httpDispatcher = $dispatcher;
$this->options = $this->configureOptions()->resolve($options);
$this->requestFactory = $requestFactory ?: Psr17FactoryDiscovery::findRequestFactory();
$this->streamFactory = $streamFactory ?: Psr17FactoryDiscovery::findStreamFactory();
Expand Down
30 changes: 10 additions & 20 deletions src/SymfonyCache/CacheEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,18 @@
*/
class CacheEvent extends BaseEvent
{
private CacheInvalidation $kernel;

private Request $request;

private ?Response $response;

private int $requestType;

/**
* Make sure your $kernel implements CacheInvalidationInterface.
*
* @param CacheInvalidation $kernel the kernel raising with this event
* @param Request $request the request being processed
* @param Response|null $response the response, if available
* @param int $requestType the request type (default HttpKernelInterface::MAIN_REQUEST)
* Make sure your $kernel implements the CacheInvalidation interface.
*/
public function __construct(CacheInvalidation $kernel, Request $request, ?Response $response = null, int $requestType = HttpKernelInterface::MAIN_REQUEST)
{
$this->kernel = $kernel;
$this->request = $request;
$this->response = $response;
$this->requestType = $requestType;
public function __construct(
/**
* The kernel raising this event.
*/
private readonly CacheInvalidation $kernel,
private readonly Request $request,
private ?Response $response = null,
private readonly int $requestType = HttpKernelInterface::MAIN_REQUEST,
) {
}

/**
Expand Down
14 changes: 6 additions & 8 deletions src/SymfonyCache/CleanupCacheTagsListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,12 @@
*/
class CleanupCacheTagsListener implements EventSubscriberInterface
{
private string $tagsHeader;

/**
* @param string $tagsHeader The header that is used for cache tags
*/
public function __construct(string $tagsHeader = TagHeaderFormatter::DEFAULT_HEADER_NAME)
{
$this->tagsHeader = $tagsHeader;
public function __construct(
/**
* The header name for setting cache tags.
*/
private readonly string $tagsHeader = TagHeaderFormatter::DEFAULT_HEADER_NAME,
) {
}

public function removeTagsHeader(CacheEvent $e): void
Expand Down
22 changes: 10 additions & 12 deletions src/SymfonyCache/CustomTtlListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,21 @@
*/
class CustomTtlListener implements EventSubscriberInterface
{
private string $ttlHeader;

private bool $keepTtlHeader;

/**
* Header used for backing up the s-maxage.
*/
public const SMAXAGE_BACKUP = 'FOS-Smaxage-Backup';

/**
* @param string $ttlHeader The header name that is used to specify the time to live
* @param bool $keepTtlHeader Keep the custom TTL header on the response for later usage (e.g. debugging)
*/
public function __construct(string $ttlHeader = 'X-Reverse-Proxy-TTL', bool $keepTtlHeader = false)
{
$this->ttlHeader = $ttlHeader;
$this->keepTtlHeader = $keepTtlHeader;
public function __construct(
/**
* The header name that is used to specify the time to live.
*/
private readonly string $ttlHeader = 'X-Reverse-Proxy-TTL',
/**
* Keep the custom TTL header on the response for later usage (e.g. debugging).
*/
private readonly bool $keepTtlHeader = false,
) {
}

/**
Expand Down
8 changes: 3 additions & 5 deletions src/SymfonyCache/KernelDispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,14 @@
*/
class KernelDispatcher implements Dispatcher
{
private HttpCacheProvider $httpCacheProvider;

/**
* @var Request[]
*/
private array $queue = [];

public function __construct(HttpCacheProvider $httpCacheProvider)
{
$this->httpCacheProvider = $httpCacheProvider;
public function __construct(
private readonly HttpCacheProvider $httpCacheProvider,
) {
}

public function invalidate(RequestInterface $invalidationRequest, bool $validateHost = true): void
Expand Down
12 changes: 4 additions & 8 deletions src/TagHeaderFormatter/CommaSeparatedTagHeaderFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,10 @@
*/
class CommaSeparatedTagHeaderFormatter implements TagHeaderFormatter, TagHeaderParser
{
private string $headerName;

private string $glue;

public function __construct(string $headerName = TagHeaderFormatter::DEFAULT_HEADER_NAME, string $glue = ',')
{
$this->headerName = $headerName;
$this->glue = $glue;
public function __construct(
private readonly string $headerName = TagHeaderFormatter::DEFAULT_HEADER_NAME,
private readonly string $glue = ',',
) {
}

public function getTagsHeaderName(): string
Expand Down
12 changes: 4 additions & 8 deletions src/TagHeaderFormatter/MaxHeaderValueLengthFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,16 @@
*/
class MaxHeaderValueLengthFormatter implements TagHeaderFormatter, TagHeaderParser
{
private TagHeaderFormatter $inner;

private int $maxHeaderValueLength;

/**
* The default value of the maximum header length is 4096 because most
* servers limit header values to 4kb.
* HTTP messages cannot carry characters outside the ISO-8859-1 standard so they all
* use up just one byte.
*/
public function __construct(TagHeaderFormatter $inner, int $maxHeaderValueLength = 4096)
{
$this->inner = $inner;
$this->maxHeaderValueLength = $maxHeaderValueLength;
public function __construct(
private readonly TagHeaderFormatter $inner,
private readonly int $maxHeaderValueLength = 4096,
) {
}

public function getTagsHeaderName(): string
Expand Down
22 changes: 10 additions & 12 deletions src/Test/HttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,16 @@ class HttpClient
*/
private ClientInterface $httpClient;

private string $hostname;

private string $port;

/**
* @param string $hostname Default hostname if not specified in the URL
* @param string $port Default port if not specified in the URL
*/
public function __construct(string $hostname, string $port)
{
$this->hostname = $hostname;
$this->port = $port;
public function __construct(
/**
* Default hostname if not specified in the URL.
*/
private readonly string $hostname,
/**
* Default port if not specified in the URL.
*/
private readonly string $port,
) {
}

/**
Expand Down
8 changes: 3 additions & 5 deletions src/Test/PHPUnit/AbstractCacheConstraint.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@

abstract class AbstractCacheConstraint extends Constraint
{
protected string $header;

public function __construct(string $header = 'X-Cache')
{
$this->header = $header;
public function __construct(
protected string $header = 'X-Cache',
) {
}

public function matches($other): bool
Expand Down