Skip to content

Commit

Permalink
Merge branch '5' into 6
Browse files Browse the repository at this point in the history
  • Loading branch information
GuySartorelli committed Sep 24, 2024
2 parents e2e3231 + a81b785 commit c523022
Show file tree
Hide file tree
Showing 20 changed files with 76 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class CliBypass implements Bypass
{
public function __construct()
{
Deprecation::withNoReplacement(function () {
Deprecation::withSuppressedNotice(function () {
Deprecation::notice(
'5.4.0',
'Will be removed without equivalent functionality to replace it',
Expand Down
2 changes: 1 addition & 1 deletion src/Dev/BuildTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public function getTitle()
*/
public function getDescription()
{
Deprecation::withNoReplacement(
Deprecation::withSuppressedNotice(
fn() => Deprecation::notice('5.4.0', 'Will be replaced with a static method with the same name')
);
return $this->description;
Expand Down
38 changes: 24 additions & 14 deletions src/Dev/Deprecation.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class Deprecation
/**
* @internal
*/
private static bool $insideWithNoReplacement = false;
private static bool $insideNoticeSuppression = false;

/**
* @internal
Expand Down Expand Up @@ -103,22 +103,32 @@ public static function disable(): void
}

/**
* Used to wrap deprecated methods and deprecated config get()/set() that will be removed
* in the next major version with no replacement. This is done to surpress deprecation notices
* by for calls from the vendor dir to deprecated code that projects have no ability to change
* Used to wrap deprecated methods and deprecated config get()/set() called from the vendor
* dir that projects have no ability to change.
*
* @return mixed
* @deprecated 5.4.0 Use withSuppressedNotice() instead
*/
public static function withNoReplacement(callable $func)
{
if (Deprecation::$insideWithNoReplacement) {
Deprecation::notice('5.4.0', 'Use withSuppressedNotice() instead');
return Deprecation::withSuppressedNotice($func);
}

/**
* Used to wrap deprecated methods and deprecated config get()/set() called from the vendor
* dir that projects have no ability to change.
*/
public static function withSuppressedNotice(callable $func): mixed
{
if (Deprecation::$insideNoticeSuppression) {
return $func();
}
Deprecation::$insideWithNoReplacement = true;
Deprecation::$insideNoticeSuppression = true;
try {
return $func();
} finally {
Deprecation::$insideWithNoReplacement = false;
Deprecation::$insideNoticeSuppression = false;
}
}

Expand All @@ -137,8 +147,8 @@ protected static function get_called_method_from_trace($backtrace, $level = 1)
$level = 1;
}
$newLevel = $level;
// handle closures inside withNoReplacement()
if (Deprecation::$insideWithNoReplacement
// handle closures inside withSuppressedNotice()
if (Deprecation::$insideNoticeSuppression
&& substr($backtrace[$newLevel]['function'], -strlen('{closure}')) === '{closure}'
) {
$newLevel = $newLevel + 2;
Expand Down Expand Up @@ -247,8 +257,8 @@ public static function outputNotices(): void
$count++;
$arr = array_shift(Deprecation::$userErrorMessageBuffer);
$message = $arr['message'];
$calledInsideWithNoReplacement = $arr['calledInsideWithNoReplacement'];
if ($calledInsideWithNoReplacement && !Deprecation::$showNoReplacementNotices) {
$calledWithNoticeSuppression = $arr['calledWithNoticeSuppression'];
if ($calledWithNoticeSuppression && !Deprecation::$showNoReplacementNotices) {
continue;
}
Deprecation::$isTriggeringError = true;
Expand Down Expand Up @@ -284,7 +294,7 @@ public static function notice($atVersion, $string = '', $scope = Deprecation::SC
$data = [
'key' => sha1($string),
'message' => $string,
'calledInsideWithNoReplacement' => Deprecation::$insideWithNoReplacement
'calledWithNoticeSuppression' => Deprecation::$insideNoticeSuppression
];
} else {
if (!Deprecation::isEnabled()) {
Expand All @@ -310,7 +320,7 @@ public static function notice($atVersion, $string = '', $scope = Deprecation::SC
$string .= ".";
}

$level = Deprecation::$insideWithNoReplacement ? 4 : 2;
$level = Deprecation::$insideNoticeSuppression ? 4 : 2;
$string .= " Called from " . Deprecation::get_called_method_from_trace($backtrace, $level) . '.';

if ($caller) {
Expand All @@ -319,7 +329,7 @@ public static function notice($atVersion, $string = '', $scope = Deprecation::SC
$data = [
'key' => sha1($string),
'message' => $string,
'calledInsideWithNoReplacement' => Deprecation::$insideWithNoReplacement
'calledWithNoticeSuppression' => Deprecation::$insideNoticeSuppression
];
}
if ($data && !array_key_exists($data['key'], Deprecation::$userErrorMessageBuffer)) {
Expand Down
2 changes: 1 addition & 1 deletion src/Dev/DevBuildController.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class DevBuildController extends Controller implements PermissionProvider
public function __construct()
{
parent::__construct();
Deprecation::withNoReplacement(function () {
Deprecation::withSuppressedNotice(function () {
Deprecation::notice(
'5.4.0',
'Will be replaced with SilverStripe\Dev\Command\DbBuild',
Expand Down
2 changes: 1 addition & 1 deletion src/Dev/DevConfigController.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class DevConfigController extends Controller implements PermissionProvider
public function __construct()
{
parent::__construct();
Deprecation::withNoReplacement(function () {
Deprecation::withSuppressedNotice(function () {
Deprecation::notice(
'5.4.0',
'Will be replaced with SilverStripe\Dev\Command\ConfigDump',
Expand Down
4 changes: 2 additions & 2 deletions src/Dev/DevelopmentAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ protected function getRegisteredController($baseUrlPart)
*/
public function buildDefaults()
{
Deprecation::withNoReplacement(function () {
Deprecation::withSuppressedNotice(function () {
Deprecation::notice(
'5.4.0',
'Will be replaced with SilverStripe\Dev\Command\DbDefaults'
Expand Down Expand Up @@ -266,7 +266,7 @@ public function buildDefaults()
*/
public function generatesecuretoken()
{
Deprecation::withNoReplacement(function () {
Deprecation::withSuppressedNotice(function () {
Deprecation::notice(
'5.4.0',
'Will be replaced with SilverStripe\Dev\Command\GenerateSecureToken'
Expand Down
2 changes: 1 addition & 1 deletion src/Dev/Tasks/CleanupTestDatabasesTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function run($request)

public function canView(): bool
{
Deprecation::withNoReplacement(function () {
Deprecation::withSuppressedNotice(function () {
Deprecation::notice(
'5.4.0',
'Will be replaced with canRunInBrowser()'
Expand Down
2 changes: 1 addition & 1 deletion src/Forms/GridField/GridFieldConfig_Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function __construct($itemsPerPage = null)
$this->addComponent(GridFieldPageCount::create('toolbar-header-right'));
$this->addComponent($pagination = GridFieldPaginator::create($itemsPerPage));

Deprecation::withNoReplacement(function () use ($sort, $filter, $pagination) {
Deprecation::withSuppressedNotice(function () use ($sort, $filter, $pagination) {
$sort->setThrowExceptionOnBadDataType(false);
$filter->setThrowExceptionOnBadDataType(false);
$pagination->setThrowExceptionOnBadDataType(false);
Expand Down
2 changes: 1 addition & 1 deletion src/Forms/GridField/GridFieldConfig_RecordEditor.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function __construct($itemsPerPage = null, $showPagination = null, $showA
$this->addComponent($pagination = GridFieldPaginator::create($itemsPerPage));
$this->addComponent(GridFieldDetailForm::create(null, $showPagination, $showAdd));

Deprecation::withNoReplacement(function () use ($sort, $filter, $pagination) {
Deprecation::withSuppressedNotice(function () use ($sort, $filter, $pagination) {
$sort->setThrowExceptionOnBadDataType(false);
$filter->setThrowExceptionOnBadDataType(false);
$pagination->setThrowExceptionOnBadDataType(false);
Expand Down
2 changes: 1 addition & 1 deletion src/Forms/GridField/GridFieldConfig_RelationEditor.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function __construct($itemsPerPage = null)
$this->addComponent($pagination = GridFieldPaginator::create($itemsPerPage));
$this->addComponent(GridFieldDetailForm::create());

Deprecation::withNoReplacement(function () use ($sort, $filter, $pagination) {
Deprecation::withSuppressedNotice(function () use ($sort, $filter, $pagination) {
$sort->setThrowExceptionOnBadDataType(false);
$filter->setThrowExceptionOnBadDataType(false);
$pagination->setThrowExceptionOnBadDataType(false);
Expand Down
7 changes: 4 additions & 3 deletions src/Logging/HTTPOutputHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Monolog\Formatter\FormatterInterface;
use Monolog\Handler\AbstractProcessingHandler;
use Monolog\Level;
use Monolog\LogRecord;
use SilverStripe\Control\Controller;
use SilverStripe\Control\Director;
Expand Down Expand Up @@ -34,10 +35,10 @@ class HTTPOutputHandler extends AbstractProcessingHandler
*/
private $cliFormatter = null;

public function __construct()
public function __construct(int|string|Level $level = Level::Debug, bool $bubble = true)
{
parent::__construct();
Deprecation::withNoReplacement(function () {
parent::__construct($level, $bubble);
Deprecation::withSuppressedNotice(function () {
Deprecation::notice(
'5.4.0',
'Will be renamed to ErrorOutputHandler',
Expand Down
2 changes: 1 addition & 1 deletion src/Model/List/ArrayList.php
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,7 @@ protected function filterOrExclude(array $filters, bool $inclusive = true, bool

// Apply default case sensitivity for backwards compatability
if (!str_contains($filterKey, ':case') && !str_contains($filterKey, ':nocase')) {
$caseSensitive = Deprecation::withNoReplacement(fn() => static::config()->get('default_case_sensitive'));
$caseSensitive = Deprecation::withSuppressedNotice(fn() => static::config()->get('default_case_sensitive'));
if ($caseSensitive && in_array('case', $searchFilter->getSupportedModifiers())) {
$searchFilter->setModifiers($searchFilter->getModifiers() + ['case']);
} elseif (!$caseSensitive && in_array('nocase', $searchFilter->getSupportedModifiers())) {
Expand Down
19 changes: 14 additions & 5 deletions src/ORM/Connect/MySQLiConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use mysqli_sql_exception;
use mysqli_stmt;
use SilverStripe\Core\Config\Config;
use SilverStripe\Core\Environment;

/**
* Connector for MySQL using the MySQLi method
Expand Down Expand Up @@ -81,15 +82,21 @@ public function connect($parameters, $selectDB = false)
// Connection charset and collation
$connCharset = Config::inst()->get(MySQLDatabase::class, 'connection_charset');
$connCollation = Config::inst()->get(MySQLDatabase::class, 'connection_collation');
$socket = Environment::getEnv('SS_DATABASE_SOCKET');
$flags = Environment::getEnv('SS_DATABASE_FLAGS');

$flags = $flags ? array_reduce(explode(',', $flags), function ($carry, $item) {
$item = trim($item);
return $carry | constant($item);
}, 0) : $flags;

$this->dbConn = mysqli_init();

// Use native types (MysqlND only)
if (defined('MYSQLI_OPT_INT_AND_FLOAT_NATIVE')) {
$this->dbConn->options(MYSQLI_OPT_INT_AND_FLOAT_NATIVE, true);

// The alternative is not ideal, throw a notice-level error
} else {
// The alternative is not ideal, throw a notice-level error
user_error(
'mysqlnd PHP library is not available, numeric values will be fetched from the DB as strings',
E_USER_NOTICE
Expand Down Expand Up @@ -117,7 +124,9 @@ public function connect($parameters, $selectDB = false)
$parameters['username'],
$parameters['password'],
$selectedDB,
!empty($parameters['port']) ? $parameters['port'] : ini_get("mysqli.default_port")
!empty($parameters['port']) ? $parameters['port'] : ini_get("mysqli.default_port"),
$socket ?? null,
$flags ?? 0
);

if ($this->dbConn->connect_error) {
Expand All @@ -126,8 +135,8 @@ public function connect($parameters, $selectDB = false)

// Set charset and collation if given and not null. Can explicitly set to empty string to omit
$charset = isset($parameters['charset'])
? $parameters['charset']
: $connCharset;
? $parameters['charset']
: $connCharset;

if (!empty($charset)) {
$this->dbConn->set_charset($charset);
Expand Down
2 changes: 1 addition & 1 deletion src/ORM/DataObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -1982,7 +1982,7 @@ public function getComponents($componentName, $id = null)
if ($details['polymorphic']) {
$result = PolymorphicHasManyList::create($componentClass, $details['joinField'], static::class);
if ($details['needsRelation']) {
Deprecation::withNoReplacement(fn () => $result->setForeignRelation($componentName));
Deprecation::withSuppressedNotice(fn () => $result->setForeignRelation($componentName));
}
} else {
$result = HasManyList::create($componentClass, $details['joinField']);
Expand Down
4 changes: 2 additions & 2 deletions src/ORM/DatabaseAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class DatabaseAdmin extends Controller
public function __construct()
{
parent::__construct();
Deprecation::withNoReplacement(function () {
Deprecation::withSuppressedNotice(function () {
Deprecation::notice(
'5.4.0',
'Will be replaced with SilverStripe\Dev\Command\DbBuild',
Expand Down Expand Up @@ -213,7 +213,7 @@ public function buildDefaults()
*/
public static function lastBuilt()
{
Deprecation::withNoReplacement(function () {
Deprecation::withSuppressedNotice(function () {
Deprecation::notice(
'5.4.0',
'Will be replaced with SilverStripe\Dev\Command\DbBuild::lastBuilt()'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ public function authenticateRequest(HTTPRequest $request)
}

// Renew the token
Deprecation::withNoReplacement(fn() => $rememberLoginHash->renew());
Deprecation::withSuppressedNotice(fn() => $rememberLoginHash->renew());

// Send the new token to the client if it was changed
if ($rememberLoginHash->getToken()) {
Expand Down
Loading

0 comments on commit c523022

Please sign in to comment.