Skip to content

Commit 5b02fe2

Browse files
Merge pull request #11480 from creative-commoners/pulls/6/php84
ENH PHP 8.4 support
2 parents 2fcf68a + 62dfe19 commit 5b02fe2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+122
-126
lines changed

src/Control/Director.php

+12-12
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@ protected static function validateUserAndPass($url)
511511
* @param HTTPRequest $request
512512
* @return string Host name, including port (if present)
513513
*/
514-
public static function host(HTTPRequest $request = null)
514+
public static function host(?HTTPRequest $request = null)
515515
{
516516
// Check if overridden by alternate_base_url
517517
if ($baseURL = static::config()->get('alternate_base_url')) {
@@ -553,7 +553,7 @@ public static function host(HTTPRequest $request = null)
553553
* @param HTTPRequest $request
554554
* @return int|null
555555
*/
556-
public static function port(HTTPRequest $request = null)
556+
public static function port(?HTTPRequest $request = null)
557557
{
558558
$host = static::host($request);
559559
return (int)parse_url($host ?? '', PHP_URL_PORT) ?: null;
@@ -565,7 +565,7 @@ public static function port(HTTPRequest $request = null)
565565
* @param HTTPRequest|null $request
566566
* @return string|null
567567
*/
568-
public static function hostName(HTTPRequest $request = null)
568+
public static function hostName(?HTTPRequest $request = null)
569569
{
570570
$host = static::host($request);
571571
return parse_url($host ?? '', PHP_URL_HOST) ?: null;
@@ -578,7 +578,7 @@ public static function hostName(HTTPRequest $request = null)
578578
* @param HTTPRequest $request
579579
* @return bool|string
580580
*/
581-
public static function protocolAndHost(HTTPRequest $request = null)
581+
public static function protocolAndHost(?HTTPRequest $request = null)
582582
{
583583
return static::protocol($request) . static::host($request);
584584
}
@@ -589,7 +589,7 @@ public static function protocolAndHost(HTTPRequest $request = null)
589589
* @param HTTPRequest $request
590590
* @return string
591591
*/
592-
public static function protocol(HTTPRequest $request = null)
592+
public static function protocol(?HTTPRequest $request = null)
593593
{
594594
return (Director::is_https($request)) ? 'https://' : 'http://';
595595
}
@@ -600,7 +600,7 @@ public static function protocol(HTTPRequest $request = null)
600600
* @param HTTPRequest $request
601601
* @return bool
602602
*/
603-
public static function is_https(HTTPRequest $request = null)
603+
public static function is_https(?HTTPRequest $request = null)
604604
{
605605
// Check override from alternate_base_url
606606
if ($baseURL = static::config()->uninherited('alternate_base_url')) {
@@ -925,7 +925,7 @@ public static function absoluteBaseURL()
925925
* @param HTTPRequest|null $request
926926
* @return string
927927
*/
928-
public static function absoluteBaseURLWithAuth(HTTPRequest $request = null)
928+
public static function absoluteBaseURLWithAuth(?HTTPRequest $request = null)
929929
{
930930
// Detect basic auth
931931
$login = '';
@@ -985,7 +985,7 @@ protected static function force_redirect($destURL)
985985
* Can include port number.
986986
* @param HTTPRequest|null $request Request object to check
987987
*/
988-
public static function forceSSL($patterns = null, $secureDomain = null, HTTPRequest $request = null)
988+
public static function forceSSL($patterns = null, $secureDomain = null, ?HTTPRequest $request = null)
989989
{
990990
$handler = CanonicalURLMiddleware::singleton()->setForceSSL(true);
991991
if ($patterns) {
@@ -1002,7 +1002,7 @@ public static function forceSSL($patterns = null, $secureDomain = null, HTTPRequ
10021002
*
10031003
* @param HTTPRequest $request
10041004
*/
1005-
public static function forceWWW(HTTPRequest $request = null)
1005+
public static function forceWWW(?HTTPRequest $request = null)
10061006
{
10071007
$handler = CanonicalURLMiddleware::singleton()->setForceWWW(true);
10081008
$handler->throwRedirectIfNeeded($request);
@@ -1018,7 +1018,7 @@ public static function forceWWW(HTTPRequest $request = null)
10181018
* @param HTTPRequest $request
10191019
* @return bool
10201020
*/
1021-
public static function is_ajax(HTTPRequest $request = null)
1021+
public static function is_ajax(?HTTPRequest $request = null)
10221022
{
10231023
$request = Director::currentRequest($request);
10241024
if ($request) {
@@ -1063,7 +1063,7 @@ public static function get_environment_type()
10631063
*
10641064
* @return string|null null if not overridden, otherwise the actual value
10651065
*/
1066-
public static function get_session_environment_type(HTTPRequest $request = null)
1066+
public static function get_session_environment_type(?HTTPRequest $request = null)
10671067
{
10681068
$request = static::currentRequest($request);
10691069

@@ -1139,7 +1139,7 @@ public static function get_template_global_variables()
11391139
* @param HTTPRequest $request
11401140
* @return HTTPRequest Request object if one is both current and valid
11411141
*/
1142-
protected static function currentRequest(HTTPRequest $request = null)
1142+
protected static function currentRequest(?HTTPRequest $request = null)
11431143
{
11441144
// Ensure we only use a registered HTTPRequest and don't
11451145
// incidentally construct a singleton

src/Control/Email/Email.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ private function getDefaultFrom(): string|array
228228
/**
229229
* Passing a string of HTML for $body will have no affect if you also call either setData() or addData()
230230
*/
231-
public function setBody(AbstractPart|string $body = null): static
231+
public function setBody(AbstractPart|string|null $body = null): static
232232
{
233233
if ($body instanceof AbstractPart) {
234234
// pass to Symfony\Component\Mime\Message::setBody()
@@ -326,7 +326,7 @@ public function addAttachment(string $path, ?string $alias = null, ?string $mime
326326
return $this->attachFromPath($path, $alias, $mime);
327327
}
328328

329-
public function addAttachmentFromData(string $data, string $name, string $mime = null): static
329+
public function addAttachmentFromData(string $data, string $name, ?string $mime = null): static
330330
{
331331
return $this->attach($data, $name, $mime);
332332
}

src/Control/Middleware/CanonicalURLMiddleware.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ protected function getRedirect(HTTPRequest $request)
310310
* @param HTTPRequest|null $request Allow HTTPRequest to be used for the base comparison
311311
* @throws HTTPResponse_Exception
312312
*/
313-
public function throwRedirectIfNeeded(HTTPRequest $request = null)
313+
public function throwRedirectIfNeeded(?HTTPRequest $request = null)
314314
{
315315
$request = $this->getOrValidateRequest($request);
316316
if (!$request) {
@@ -328,7 +328,7 @@ public function throwRedirectIfNeeded(HTTPRequest $request = null)
328328
* @param HTTPRequest $request
329329
* @return HTTPRequest|null
330330
*/
331-
protected function getOrValidateRequest(HTTPRequest $request = null)
331+
protected function getOrValidateRequest(?HTTPRequest $request = null)
332332
{
333333
if ($request instanceof HTTPRequest) {
334334
return $request;
@@ -526,7 +526,7 @@ protected function isEnabled()
526526
* @param HTTPResponse $response
527527
* @return bool
528528
*/
529-
protected function hasBasicAuthPrompt(HTTPResponse $response = null)
529+
protected function hasBasicAuthPrompt(?HTTPResponse $response = null)
530530
{
531531
if (!$response) {
532532
return false;

src/Control/Middleware/RequestHandlerMiddlewareAdapter.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class RequestHandlerMiddlewareAdapter extends RequestHandler
1818
*/
1919
protected $requestHandler = null;
2020

21-
public function __construct(RequestHandler $handler = null)
21+
public function __construct(?RequestHandler $handler = null)
2222
{
2323
if ($handler) {
2424
$this->setRequestHandler($handler);

src/Control/PjaxResponseNegotiator.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class PjaxResponseNegotiator
4141
* @param array $callbacks
4242
* @param HTTPResponse $response An existing response to reuse (optional)
4343
*/
44-
public function __construct($callbacks = [], HTTPResponse $response = null)
44+
public function __construct($callbacks = [], ?HTTPResponse $response = null)
4545
{
4646
$this->callbacks = $callbacks;
4747
$this->response = $response ?: HTTPResponse::create();

src/Control/Session.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ private function isCookieSecure(string $sameSite, bool $isHttps): bool
404404
* @param bool $removeCookie
405405
* @param HTTPRequest $request The request for which to destroy a session
406406
*/
407-
public function destroy($removeCookie = true, HTTPRequest $request = null)
407+
public function destroy($removeCookie = true, ?HTTPRequest $request = null)
408408
{
409409
if (session_id()) {
410410
if ($removeCookie) {

src/Core/BaseKernel.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,10 @@ protected function bootPHP()
141141
{
142142
if ($this->getEnvironment() === BaseKernel::LIVE) {
143143
// limited to fatal errors and warnings in live mode
144-
error_reporting(E_ALL & ~(E_DEPRECATED | E_STRICT | E_NOTICE));
144+
error_reporting(E_ALL & ~(E_DEPRECATED | E_NOTICE));
145145
} else {
146146
// Report all errors in dev / test mode
147-
error_reporting(E_ALL | E_STRICT);
147+
error_reporting(E_ALL);
148148
}
149149

150150
/**

src/Core/Cache/AbstractCacheFactory.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ abstract class AbstractCacheFactory implements CacheFactory
2020
/**
2121
* @param LoggerInterface $logger Logger instance to assign
2222
*/
23-
public function __construct(LoggerInterface $logger = null)
23+
public function __construct(?LoggerInterface $logger = null)
2424
{
2525
$this->logger = $logger;
2626
}

src/Core/Cache/DefaultCacheFactory.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class DefaultCacheFactory extends AbstractCacheFactory
2525
* @param array $args List of global options to merge with args during create()
2626
* @param LoggerInterface $logger Logger instance to assign
2727
*/
28-
public function __construct($args = [], LoggerInterface $logger = null)
28+
public function __construct($args = [], ?LoggerInterface $logger = null)
2929
{
3030
$this->args = $args;
3131
parent::__construct($logger);

src/Core/Cache/ManifestCacheFactory.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
*/
1818
class ManifestCacheFactory extends DefaultCacheFactory
1919
{
20-
public function __construct(array $args = [], LoggerInterface $logger = null)
20+
public function __construct(array $args = [], ?LoggerInterface $logger = null)
2121
{
2222
// Build default manifest logger
2323
if (!$logger) {

src/Core/Config/CoreConfigFactory.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class CoreConfigFactory
3333
*
3434
* @param CacheFactory $cacheFactory
3535
*/
36-
public function __construct(CacheFactory $cacheFactory = null)
36+
public function __construct(?CacheFactory $cacheFactory = null)
3737
{
3838
$this->cacheFactory = $cacheFactory;
3939
}

src/Core/Manifest/ClassManifest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ class ClassManifest
198198
* @param string $base The manifest base path.
199199
* @param CacheFactory $cacheFactory Optional cache to use. Set to null to not cache.
200200
*/
201-
public function __construct($base, CacheFactory $cacheFactory = null)
201+
public function __construct($base, ?CacheFactory $cacheFactory = null)
202202
{
203203
$this->base = $base;
204204
$this->cacheFactory = $cacheFactory;

src/Core/Manifest/ModuleManifest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class ModuleManifest
7373
* @param string $base The project base path.
7474
* @param CacheFactory $cacheFactory Cache factory to use
7575
*/
76-
public function __construct($base, CacheFactory $cacheFactory = null)
76+
public function __construct($base, ?CacheFactory $cacheFactory = null)
7777
{
7878
$this->base = $base;
7979
$this->cacheKey = sha1($base ?? '') . '_modules';

src/Core/Validation/FieldValidation/DecimalFieldValidator.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ public function __construct(
3939
mixed $value,
4040
int $wholeSize,
4141
int $decimalSize,
42-
int $minValue = null,
43-
int $maxValue = null,
42+
?int $minValue = null,
43+
?int $maxValue = null,
4444
) {
4545
parent::__construct($name, $value, $minValue, $maxValue);
4646
$this->wholeSize = $wholeSize;

src/Dev/Debug.php

+7-7
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class Debug
3838
* @param bool $showHeader
3939
* @param HTTPRequest|null $request
4040
*/
41-
public static function show($val, $showHeader = true, HTTPRequest $request = null)
41+
public static function show($val, $showHeader = true, ?HTTPRequest $request = null)
4242
{
4343
// Don't show on live
4444
if (Director::isLive()) {
@@ -80,7 +80,7 @@ public static function caller()
8080
* @param bool $showHeader
8181
* @param HTTPRequest $request
8282
*/
83-
public static function endshow($val, $showHeader = true, HTTPRequest $request = null)
83+
public static function endshow($val, $showHeader = true, ?HTTPRequest $request = null)
8484
{
8585
// Don't show on live
8686
if (Director::isLive()) {
@@ -100,7 +100,7 @@ public static function endshow($val, $showHeader = true, HTTPRequest $request =
100100
* @param mixed $val
101101
* @param HTTPRequest $request Current request to influence output format
102102
*/
103-
public static function dump($val, HTTPRequest $request = null)
103+
public static function dump($val, ?HTTPRequest $request = null)
104104
{
105105
echo Debug::create_debug_view($request)
106106
->renderVariable($val, Debug::caller());
@@ -113,7 +113,7 @@ public static function dump($val, HTTPRequest $request = null)
113113
* @param HTTPRequest $request
114114
* @return string
115115
*/
116-
public static function text($val, HTTPRequest $request = null)
116+
public static function text($val, ?HTTPRequest $request = null)
117117
{
118118
return static::create_debug_view($request)
119119
->debugVariableText($val);
@@ -127,7 +127,7 @@ public static function text($val, HTTPRequest $request = null)
127127
* @param bool $showHeader
128128
* @param HTTPRequest|null $request
129129
*/
130-
public static function message($message, $showHeader = true, HTTPRequest $request = null)
130+
public static function message($message, $showHeader = true, ?HTTPRequest $request = null)
131131
{
132132
// Don't show on live
133133
if (Director::isLive()) {
@@ -144,7 +144,7 @@ public static function message($message, $showHeader = true, HTTPRequest $reques
144144
* @param HTTPRequest $request Optional request to target this view for
145145
* @return DebugView
146146
*/
147-
public static function create_debug_view(HTTPRequest $request = null)
147+
public static function create_debug_view(?HTTPRequest $request = null)
148148
{
149149
$service = static::supportsHTML($request)
150150
? DebugView::class
@@ -158,7 +158,7 @@ public static function create_debug_view(HTTPRequest $request = null)
158158
* @param HTTPRequest $request
159159
* @return bool
160160
*/
161-
protected static function supportsHTML(HTTPRequest $request = null)
161+
protected static function supportsHTML(?HTTPRequest $request = null)
162162
{
163163
// No HTML output in CLI
164164
if (Director::is_cli()) {

src/Dev/DebugView.php

-4
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,6 @@ class DebugView
102102
'title' => 'User Warning',
103103
'class' => 'warning'
104104
],
105-
E_STRICT => [
106-
'title' => 'Strict Notice',
107-
'class' => 'notice'
108-
],
109105
E_RECOVERABLE_ERROR => [
110106
'title' => 'Recoverable Error',
111107
'class' => 'warning'

src/Dev/Deprecation.php

+8-4
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,14 @@ private static function get_called_from_trace(array $backtrace, int $level): arr
169169
{
170170
$newLevel = $level;
171171
// handle closures inside withSuppressedNotice()
172-
if (Deprecation::$insideNoticeSuppression
173-
&& substr($backtrace[$newLevel]['function'], -strlen('{closure}')) === '{closure}'
174-
) {
175-
$newLevel = $newLevel + 2;
172+
if (Deprecation::$insideNoticeSuppression) {
173+
$func = $backtrace[$newLevel]['function'];
174+
// different versions of php have different formats for closures
175+
// php <=8.3 example "SilverStripe\Dev\{closure}"
176+
// php >=8.4 example "{closure:SilverStripe\Dev\Deprecation::noticeWithNoReplacment():464}"
177+
if (str_ends_with($func, '{closure}') || str_starts_with($func, '{closure:')) {
178+
$newLevel = $newLevel + 2;
179+
}
176180
}
177181
// handle call_user_func
178182
if ($level === 4 && strpos($backtrace[2]['function'] ?? '', 'call_user_func') !== false) {

src/Dev/FunctionalTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ public function post($url, $data, $headers = null, $session = null, $body = null
191191
* @param array $data Map of GET/POST data.
192192
* @param bool $withSecurityToken Submit with the form's security token if there is one.
193193
*/
194-
public function submitForm(string $formID, string $button = null, array $data = [], bool $withSecurityToken = true): HTTPResponse
194+
public function submitForm(string $formID, ?string $button = null, array $data = [], bool $withSecurityToken = true): HTTPResponse
195195
{
196196
$this->cssParser = null;
197197
$response = $this->mainSession->submitForm($formID, $button, $data, $withSecurityToken);

src/Dev/TestMailer.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function __construct(
3333
$this->dispatcher = $dispatcher;
3434
}
3535

36-
public function send(RawMessage $message, Envelope $envelope = null): void
36+
public function send(RawMessage $message, ?Envelope $envelope = null): void
3737
{
3838
if (!is_a($message, Email::class)) {
3939
throw new InvalidArgumentException('$message must be a ' . Email::class);
@@ -122,7 +122,7 @@ private function convertAddressesToString(array $addresses): string
122122
return implode(',', array_map(fn(Address $address) => $address->getAddress(), $addresses));
123123
}
124124

125-
private function dispatchEvent(Email $email, Envelope $envelope = null): void
125+
private function dispatchEvent(Email $email, ?Envelope $envelope = null): void
126126
{
127127
$sender = $email->getSender()[0] ?? $email->getFrom()[0] ?? new Address('[email protected]');
128128
$recipients = empty($email->getTo()) ? [new Address('[email protected]')] : $email->getTo();

src/Dev/TestSession.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ public function sendRequest($method, $url, $data, $headers = null, $session = nu
207207
* @param array $data Map of GET/POST data.
208208
* @param bool $withSecurityToken Submit with the form's security token if there is one.
209209
*/
210-
public function submitForm(string $formID, string $button = null, array $data = [], bool $withSecurityToken = true): HTTPResponse
210+
public function submitForm(string $formID, ?string $button = null, array $data = [], bool $withSecurityToken = true): HTTPResponse
211211
{
212212
$page = $this->lastPage();
213213
if ($page) {

0 commit comments

Comments
 (0)