Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH PHP 8.4 support #11480

Merged
merged 5 commits into from
Dec 3, 2024
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
24 changes: 12 additions & 12 deletions src/Control/Director.php
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ protected static function validateUserAndPass($url)
* @param HTTPRequest $request
* @return string Host name, including port (if present)
*/
public static function host(HTTPRequest $request = null)
public static function host(?HTTPRequest $request = null)
{
// Check if overridden by alternate_base_url
if ($baseURL = static::config()->get('alternate_base_url')) {
Expand Down Expand Up @@ -553,7 +553,7 @@ public static function host(HTTPRequest $request = null)
* @param HTTPRequest $request
* @return int|null
*/
public static function port(HTTPRequest $request = null)
public static function port(?HTTPRequest $request = null)
{
$host = static::host($request);
return (int)parse_url($host ?? '', PHP_URL_PORT) ?: null;
Expand All @@ -565,7 +565,7 @@ public static function port(HTTPRequest $request = null)
* @param HTTPRequest|null $request
* @return string|null
*/
public static function hostName(HTTPRequest $request = null)
public static function hostName(?HTTPRequest $request = null)
{
$host = static::host($request);
return parse_url($host ?? '', PHP_URL_HOST) ?: null;
Expand All @@ -578,7 +578,7 @@ public static function hostName(HTTPRequest $request = null)
* @param HTTPRequest $request
* @return bool|string
*/
public static function protocolAndHost(HTTPRequest $request = null)
public static function protocolAndHost(?HTTPRequest $request = null)
{
return static::protocol($request) . static::host($request);
}
Expand All @@ -589,7 +589,7 @@ public static function protocolAndHost(HTTPRequest $request = null)
* @param HTTPRequest $request
* @return string
*/
public static function protocol(HTTPRequest $request = null)
public static function protocol(?HTTPRequest $request = null)
{
return (Director::is_https($request)) ? 'https://' : 'http://';
}
Expand All @@ -600,7 +600,7 @@ public static function protocol(HTTPRequest $request = null)
* @param HTTPRequest $request
* @return bool
*/
public static function is_https(HTTPRequest $request = null)
public static function is_https(?HTTPRequest $request = null)
{
// Check override from alternate_base_url
if ($baseURL = static::config()->uninherited('alternate_base_url')) {
Expand Down Expand Up @@ -925,7 +925,7 @@ public static function absoluteBaseURL()
* @param HTTPRequest|null $request
* @return string
*/
public static function absoluteBaseURLWithAuth(HTTPRequest $request = null)
public static function absoluteBaseURLWithAuth(?HTTPRequest $request = null)
{
// Detect basic auth
$login = '';
Expand Down Expand Up @@ -985,7 +985,7 @@ protected static function force_redirect($destURL)
* Can include port number.
* @param HTTPRequest|null $request Request object to check
*/
public static function forceSSL($patterns = null, $secureDomain = null, HTTPRequest $request = null)
public static function forceSSL($patterns = null, $secureDomain = null, ?HTTPRequest $request = null)
{
$handler = CanonicalURLMiddleware::singleton()->setForceSSL(true);
if ($patterns) {
Expand All @@ -1002,7 +1002,7 @@ public static function forceSSL($patterns = null, $secureDomain = null, HTTPRequ
*
* @param HTTPRequest $request
*/
public static function forceWWW(HTTPRequest $request = null)
public static function forceWWW(?HTTPRequest $request = null)
{
$handler = CanonicalURLMiddleware::singleton()->setForceWWW(true);
$handler->throwRedirectIfNeeded($request);
Expand All @@ -1018,7 +1018,7 @@ public static function forceWWW(HTTPRequest $request = null)
* @param HTTPRequest $request
* @return bool
*/
public static function is_ajax(HTTPRequest $request = null)
public static function is_ajax(?HTTPRequest $request = null)
{
$request = Director::currentRequest($request);
if ($request) {
Expand Down Expand Up @@ -1063,7 +1063,7 @@ public static function get_environment_type()
*
* @return string|null null if not overridden, otherwise the actual value
*/
public static function get_session_environment_type(HTTPRequest $request = null)
public static function get_session_environment_type(?HTTPRequest $request = null)
{
$request = static::currentRequest($request);

Expand Down Expand Up @@ -1139,7 +1139,7 @@ public static function get_template_global_variables()
* @param HTTPRequest $request
* @return HTTPRequest Request object if one is both current and valid
*/
protected static function currentRequest(HTTPRequest $request = null)
protected static function currentRequest(?HTTPRequest $request = null)
{
// Ensure we only use a registered HTTPRequest and don't
// incidentally construct a singleton
Expand Down
4 changes: 2 additions & 2 deletions src/Control/Email/Email.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ private function getDefaultFrom(): string|array
/**
* Passing a string of HTML for $body will have no affect if you also call either setData() or addData()
*/
public function setBody(AbstractPart|string $body = null): static
public function setBody(AbstractPart|string|null $body = null): static
{
if ($body instanceof AbstractPart) {
// pass to Symfony\Component\Mime\Message::setBody()
Expand Down Expand Up @@ -326,7 +326,7 @@ public function addAttachment(string $path, ?string $alias = null, ?string $mime
return $this->attachFromPath($path, $alias, $mime);
}

public function addAttachmentFromData(string $data, string $name, string $mime = null): static
public function addAttachmentFromData(string $data, string $name, ?string $mime = null): static
{
return $this->attach($data, $name, $mime);
}
Expand Down
6 changes: 3 additions & 3 deletions src/Control/Middleware/CanonicalURLMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ protected function getRedirect(HTTPRequest $request)
* @param HTTPRequest|null $request Allow HTTPRequest to be used for the base comparison
* @throws HTTPResponse_Exception
*/
public function throwRedirectIfNeeded(HTTPRequest $request = null)
public function throwRedirectIfNeeded(?HTTPRequest $request = null)
{
$request = $this->getOrValidateRequest($request);
if (!$request) {
Expand All @@ -328,7 +328,7 @@ public function throwRedirectIfNeeded(HTTPRequest $request = null)
* @param HTTPRequest $request
* @return HTTPRequest|null
*/
protected function getOrValidateRequest(HTTPRequest $request = null)
protected function getOrValidateRequest(?HTTPRequest $request = null)
{
if ($request instanceof HTTPRequest) {
return $request;
Expand Down Expand Up @@ -526,7 +526,7 @@ protected function isEnabled()
* @param HTTPResponse $response
* @return bool
*/
protected function hasBasicAuthPrompt(HTTPResponse $response = null)
protected function hasBasicAuthPrompt(?HTTPResponse $response = null)
{
if (!$response) {
return false;
Expand Down
2 changes: 1 addition & 1 deletion src/Control/Middleware/RequestHandlerMiddlewareAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class RequestHandlerMiddlewareAdapter extends RequestHandler
*/
protected $requestHandler = null;

public function __construct(RequestHandler $handler = null)
public function __construct(?RequestHandler $handler = null)
{
if ($handler) {
$this->setRequestHandler($handler);
Expand Down
2 changes: 1 addition & 1 deletion src/Control/PjaxResponseNegotiator.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class PjaxResponseNegotiator
* @param array $callbacks
* @param HTTPResponse $response An existing response to reuse (optional)
*/
public function __construct($callbacks = [], HTTPResponse $response = null)
public function __construct($callbacks = [], ?HTTPResponse $response = null)
{
$this->callbacks = $callbacks;
$this->response = $response ?: HTTPResponse::create();
Expand Down
2 changes: 1 addition & 1 deletion src/Control/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ private function isCookieSecure(string $sameSite, bool $isHttps): bool
* @param bool $removeCookie
* @param HTTPRequest $request The request for which to destroy a session
*/
public function destroy($removeCookie = true, HTTPRequest $request = null)
public function destroy($removeCookie = true, ?HTTPRequest $request = null)
{
if (session_id()) {
if ($removeCookie) {
Expand Down
4 changes: 2 additions & 2 deletions src/Core/BaseKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,10 @@ protected function bootPHP()
{
if ($this->getEnvironment() === BaseKernel::LIVE) {
// limited to fatal errors and warnings in live mode
error_reporting(E_ALL & ~(E_DEPRECATED | E_STRICT | E_NOTICE));
error_reporting(E_ALL & ~(E_DEPRECATED | E_NOTICE));
} else {
// Report all errors in dev / test mode
error_reporting(E_ALL | E_STRICT);
error_reporting(E_ALL);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Cache/AbstractCacheFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ abstract class AbstractCacheFactory implements CacheFactory
/**
* @param LoggerInterface $logger Logger instance to assign
*/
public function __construct(LoggerInterface $logger = null)
public function __construct(?LoggerInterface $logger = null)
{
$this->logger = $logger;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Cache/DefaultCacheFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class DefaultCacheFactory extends AbstractCacheFactory
* @param array $args List of global options to merge with args during create()
* @param LoggerInterface $logger Logger instance to assign
*/
public function __construct($args = [], LoggerInterface $logger = null)
public function __construct($args = [], ?LoggerInterface $logger = null)
{
$this->args = $args;
parent::__construct($logger);
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Cache/ManifestCacheFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/
class ManifestCacheFactory extends DefaultCacheFactory
{
public function __construct(array $args = [], LoggerInterface $logger = null)
public function __construct(array $args = [], ?LoggerInterface $logger = null)
{
// Build default manifest logger
if (!$logger) {
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Config/CoreConfigFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class CoreConfigFactory
*
* @param CacheFactory $cacheFactory
*/
public function __construct(CacheFactory $cacheFactory = null)
public function __construct(?CacheFactory $cacheFactory = null)
{
$this->cacheFactory = $cacheFactory;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Manifest/ClassManifest.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ class ClassManifest
* @param string $base The manifest base path.
* @param CacheFactory $cacheFactory Optional cache to use. Set to null to not cache.
*/
public function __construct($base, CacheFactory $cacheFactory = null)
public function __construct($base, ?CacheFactory $cacheFactory = null)
{
$this->base = $base;
$this->cacheFactory = $cacheFactory;
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Manifest/ModuleManifest.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class ModuleManifest
* @param string $base The project base path.
* @param CacheFactory $cacheFactory Cache factory to use
*/
public function __construct($base, CacheFactory $cacheFactory = null)
public function __construct($base, ?CacheFactory $cacheFactory = null)
{
$this->base = $base;
$this->cacheKey = sha1($base ?? '') . '_modules';
Expand Down
4 changes: 2 additions & 2 deletions src/Core/Validation/FieldValidation/DecimalFieldValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ public function __construct(
mixed $value,
int $wholeSize,
int $decimalSize,
int $minValue = null,
int $maxValue = null,
?int $minValue = null,
?int $maxValue = null,
) {
parent::__construct($name, $value, $minValue, $maxValue);
$this->wholeSize = $wholeSize;
Expand Down
14 changes: 7 additions & 7 deletions src/Dev/Debug.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class Debug
* @param bool $showHeader
* @param HTTPRequest|null $request
*/
public static function show($val, $showHeader = true, HTTPRequest $request = null)
public static function show($val, $showHeader = true, ?HTTPRequest $request = null)
{
// Don't show on live
if (Director::isLive()) {
Expand Down Expand Up @@ -80,7 +80,7 @@ public static function caller()
* @param bool $showHeader
* @param HTTPRequest $request
*/
public static function endshow($val, $showHeader = true, HTTPRequest $request = null)
public static function endshow($val, $showHeader = true, ?HTTPRequest $request = null)
{
// Don't show on live
if (Director::isLive()) {
Expand All @@ -100,7 +100,7 @@ public static function endshow($val, $showHeader = true, HTTPRequest $request =
* @param mixed $val
* @param HTTPRequest $request Current request to influence output format
*/
public static function dump($val, HTTPRequest $request = null)
public static function dump($val, ?HTTPRequest $request = null)
{
echo Debug::create_debug_view($request)
->renderVariable($val, Debug::caller());
Expand All @@ -113,7 +113,7 @@ public static function dump($val, HTTPRequest $request = null)
* @param HTTPRequest $request
* @return string
*/
public static function text($val, HTTPRequest $request = null)
public static function text($val, ?HTTPRequest $request = null)
{
return static::create_debug_view($request)
->debugVariableText($val);
Expand All @@ -127,7 +127,7 @@ public static function text($val, HTTPRequest $request = null)
* @param bool $showHeader
* @param HTTPRequest|null $request
*/
public static function message($message, $showHeader = true, HTTPRequest $request = null)
public static function message($message, $showHeader = true, ?HTTPRequest $request = null)
{
// Don't show on live
if (Director::isLive()) {
Expand All @@ -144,7 +144,7 @@ public static function message($message, $showHeader = true, HTTPRequest $reques
* @param HTTPRequest $request Optional request to target this view for
* @return DebugView
*/
public static function create_debug_view(HTTPRequest $request = null)
public static function create_debug_view(?HTTPRequest $request = null)
{
$service = static::supportsHTML($request)
? DebugView::class
Expand All @@ -158,7 +158,7 @@ public static function create_debug_view(HTTPRequest $request = null)
* @param HTTPRequest $request
* @return bool
*/
protected static function supportsHTML(HTTPRequest $request = null)
protected static function supportsHTML(?HTTPRequest $request = null)
{
// No HTML output in CLI
if (Director::is_cli()) {
Expand Down
4 changes: 0 additions & 4 deletions src/Dev/DebugView.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,6 @@ class DebugView
'title' => 'User Warning',
'class' => 'warning'
],
E_STRICT => [
'title' => 'Strict Notice',
'class' => 'notice'
],
E_RECOVERABLE_ERROR => [
'title' => 'Recoverable Error',
'class' => 'warning'
Expand Down
12 changes: 8 additions & 4 deletions src/Dev/Deprecation.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,14 @@ private static function get_called_from_trace(array $backtrace, int $level): arr
{
$newLevel = $level;
// handle closures inside withSuppressedNotice()
if (Deprecation::$insideNoticeSuppression
&& substr($backtrace[$newLevel]['function'], -strlen('{closure}')) === '{closure}'
) {
$newLevel = $newLevel + 2;
if (Deprecation::$insideNoticeSuppression) {
GuySartorelli marked this conversation as resolved.
Show resolved Hide resolved
$func = $backtrace[$newLevel]['function'];
// different versions of php have different formats for closures
// php <=8.3 example "SilverStripe\Dev\{closure}"
// php >=8.4 example "{closure:SilverStripe\Dev\Deprecation::noticeWithNoReplacment():464}"
if (str_ends_with($func, '{closure}') || str_starts_with($func, '{closure:')) {
$newLevel = $newLevel + 2;
}
}
// handle call_user_func
if ($level === 4 && strpos($backtrace[2]['function'] ?? '', 'call_user_func') !== false) {
Expand Down
2 changes: 1 addition & 1 deletion src/Dev/FunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public function post($url, $data, $headers = null, $session = null, $body = null
* @param array $data Map of GET/POST data.
* @param bool $withSecurityToken Submit with the form's security token if there is one.
*/
public function submitForm(string $formID, string $button = null, array $data = [], bool $withSecurityToken = true): HTTPResponse
public function submitForm(string $formID, ?string $button = null, array $data = [], bool $withSecurityToken = true): HTTPResponse
{
$this->cssParser = null;
$response = $this->mainSession->submitForm($formID, $button, $data, $withSecurityToken);
Expand Down
4 changes: 2 additions & 2 deletions src/Dev/TestMailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function __construct(
$this->dispatcher = $dispatcher;
}

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

private function dispatchEvent(Email $email, Envelope $envelope = null): void
private function dispatchEvent(Email $email, ?Envelope $envelope = null): void
{
$sender = $email->getSender()[0] ?? $email->getFrom()[0] ?? new Address('[email protected]');
$recipients = empty($email->getTo()) ? [new Address('[email protected]')] : $email->getTo();
Expand Down
2 changes: 1 addition & 1 deletion src/Dev/TestSession.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ public function sendRequest($method, $url, $data, $headers = null, $session = nu
* @param array $data Map of GET/POST data.
* @param bool $withSecurityToken Submit with the form's security token if there is one.
*/
public function submitForm(string $formID, string $button = null, array $data = [], bool $withSecurityToken = true): HTTPResponse
public function submitForm(string $formID, ?string $button = null, array $data = [], bool $withSecurityToken = true): HTTPResponse
{
$page = $this->lastPage();
if ($page) {
Expand Down
Loading
Loading