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

WIP: Add PHP 8.4 support #11485

Closed
Closed
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 @@ -486,7 +486,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 @@ -528,7 +528,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 @@ -540,7 +540,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 @@ -553,7 +553,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 @@ -564,7 +564,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 @@ -575,7 +575,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 @@ -900,7 +900,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 @@ -960,7 +960,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 @@ -977,7 +977,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 @@ -993,7 +993,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 @@ -1038,7 +1038,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 @@ -1114,7 +1114,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 @@ -226,7 +226,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 @@ -324,7 +324,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 @@ -308,7 +308,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 @@ -326,7 +326,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 @@ -524,7 +524,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
8 changes: 4 additions & 4 deletions src/Core/BaseKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace SilverStripe\Core;

use Exception;
use InvalidArgumentException;
use Monolog\Handler\StreamHandler;
use Monolog\Logger;
Expand All @@ -21,13 +22,12 @@
use SilverStripe\Core\Manifest\ModuleLoader;
use SilverStripe\Core\Manifest\ModuleManifest;
use SilverStripe\Dev\DebugView;
use SilverStripe\Dev\Deprecation;
use SilverStripe\Logging\ErrorHandler;
use SilverStripe\View\PublicThemes;
use SilverStripe\View\SSViewer;
use SilverStripe\View\ThemeManifest;
use SilverStripe\View\ThemeResourceLoader;
use Exception;
use SilverStripe\Dev\Deprecation;

/**
* Simple Kernel container
Expand Down Expand Up @@ -142,10 +142,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/DefaultCacheFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class DefaultCacheFactory implements CacheFactory
* @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;
$this->logger = $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/Cache/MemcachedCacheFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class MemcachedCacheFactory implements CacheFactory
/**
* @param Memcached $memcachedClient
*/
public function __construct(Memcached $memcachedClient = null)
public function __construct(?Memcached $memcachedClient = null)
{
$this->memcachedClient = $memcachedClient;
}
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
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
2 changes: 1 addition & 1 deletion src/Dev/FunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,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('test.sender@example.com');
$recipients = empty($email->getTo()) ? [new Address('test.recipient@example.com')] : $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 @@ -206,7 +206,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