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

API Rename Deprecation::withNoReplacement #11390

Merged
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
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/Core/CoreKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ protected function validateDatabase()
$msg = 'Silverstripe Framework requires a "database" key in DB::getConfig(). ' .
'Did you forget to set SS_DATABASE_NAME or SS_DATABASE_CHOOSE_NAME in your environment?';
$this->detectLegacyEnvironment();
Deprecation::withNoReplacement(fn() => $this->redirectToInstaller($msg));
Deprecation::withSuppressedNotice(fn() => $this->redirectToInstaller($msg));
}
}

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/SSListExporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class SSListExporter extends Exporter implements TestOnly
{
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/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
2 changes: 1 addition & 1 deletion src/Logging/HTTPOutputHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class HTTPOutputHandler extends AbstractProcessingHandler
public function __construct()
{
parent::__construct();
Deprecation::withNoReplacement(function () {
Deprecation::withSuppressedNotice(function () {
Deprecation::notice(
'5.4.0',
'Will be renamed to ErrorOutputHandler',
Expand Down
24 changes: 12 additions & 12 deletions src/ORM/ArrayLib.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class ArrayLib
{
public function __construct()
{
Deprecation::withNoReplacement(function () {
Deprecation::withSuppressedNotice(function () {
Deprecation::notice('5.4.0', 'Will be renamed to SilverStripe\Core\ArrayLib', Deprecation::SCOPE_CLASS);
});
}
Expand Down Expand Up @@ -58,7 +58,7 @@ public function __construct()
*/
public static function invert($arr)
{
Deprecation::withNoReplacement(function () {
Deprecation::withSuppressedNotice(function () {
Deprecation::notice('5.4.0', 'Will be renamed to SilverStripe\Core\ArrayLib::invert()');
});

Expand Down Expand Up @@ -86,7 +86,7 @@ public static function invert($arr)
*/
public static function valuekey($arr)
{
Deprecation::withNoReplacement(function () {
Deprecation::withSuppressedNotice(function () {
Deprecation::notice('5.4.0', 'Will be renamed to SilverStripe\Core\ArrayLib::valuekey()');
});

Expand All @@ -102,7 +102,7 @@ public static function valuekey($arr)
*/
public static function array_values_recursive($array)
{
Deprecation::withNoReplacement(function () {
Deprecation::withSuppressedNotice(function () {
Deprecation::notice('5.4.0', 'Will be renamed to SilverStripe\Core\ArrayLib::invearray_values_recursivert()');
});

Expand All @@ -121,7 +121,7 @@ public static function array_values_recursive($array)
*/
public static function filter_keys($arr, $keys)
{
Deprecation::withNoReplacement(function () {
Deprecation::withSuppressedNotice(function () {
Deprecation::notice('5.4.0', 'Will be renamed to SilverStripe\Core\ArrayLib::filter_keys()');
});

Expand All @@ -147,7 +147,7 @@ public static function filter_keys($arr, $keys)
*/
public static function is_associative($array)
{
Deprecation::withNoReplacement(function () {
Deprecation::withSuppressedNotice(function () {
Deprecation::notice('5.4.0', 'Will be renamed to SilverStripe\Core\ArrayLib::is_associative()');
});

Expand All @@ -173,7 +173,7 @@ public static function is_associative($array)
*/
public static function in_array_recursive($needle, $haystack, $strict = false)
{
Deprecation::withNoReplacement(function () {
Deprecation::withSuppressedNotice(function () {
Deprecation::notice('5.4.0', 'Will be renamed to SilverStripe\Core\ArrayLib::in_array_recursive()');
});

Expand Down Expand Up @@ -206,7 +206,7 @@ public static function in_array_recursive($needle, $haystack, $strict = false)
*/
public static function array_map_recursive($f, $array)
{
Deprecation::withNoReplacement(function () {
Deprecation::withSuppressedNotice(function () {
Deprecation::notice('5.4.0', 'Will be renamed to SilverStripe\Core\ArrayLib::array_map_recursive()');
});

Expand All @@ -232,7 +232,7 @@ public static function array_map_recursive($f, $array)
*/
public static function array_merge_recursive($array)
{
Deprecation::withNoReplacement(function () {
Deprecation::withSuppressedNotice(function () {
Deprecation::notice('5.4.0', 'Will be renamed to SilverStripe\Core\ArrayLib::array_merge_recursive()');
});

Expand Down Expand Up @@ -282,7 +282,7 @@ public static function array_merge_recursive($array)
*/
public static function flatten($array, $preserveKeys = true, &$out = [])
{
Deprecation::withNoReplacement(function () {
Deprecation::withSuppressedNotice(function () {
Deprecation::notice('5.4.0', 'Will be renamed to SilverStripe\Core\ArrayLib::flatten()');
});

Expand Down Expand Up @@ -314,7 +314,7 @@ function ($value, $key) use (&$out, $preserveKeys) {
*/
public static function iterateVolatile(array &$list)
{
Deprecation::withNoReplacement(function () {
Deprecation::withSuppressedNotice(function () {
Deprecation::notice('5.4.0', 'Will be renamed to SilverStripe\Core\ArrayLib::iterateVolatile()');
});

Expand All @@ -341,7 +341,7 @@ public static function iterateVolatile(array &$list)
*/
public static function shuffleAssociative(array &$array): void
{
Deprecation::withNoReplacement(function () {
Deprecation::withSuppressedNotice(function () {
Deprecation::notice('5.4.0', 'Will be renamed to SilverStripe\Core\ArrayLib::shuffleAssociative()');
});

Expand Down
4 changes: 2 additions & 2 deletions src/ORM/ArrayList.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class ArrayList extends ViewableData implements SS_List, Filterable, Sortable, L
*/
public function __construct(array $items = [])
{
Deprecation::withNoReplacement(function () {
Deprecation::withSuppressedNotice(function () {
Deprecation::notice('5.4.0', 'Will be renamed to SilverStripe\Model\List\ArrayList', Deprecation::SCOPE_CLASS);
});

Expand Down Expand Up @@ -731,7 +731,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
4 changes: 2 additions & 2 deletions src/ORM/DataExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ abstract class DataExtension extends Extension
{
public function __construct()
{
// Wrapping with Deprecation::withNoReplacement() to avoid triggering deprecation notices
// Wrapping with Deprecation::withSuppressedNotice() to avoid triggering deprecation notices
// as we are unable to update existing subclasses of this class until a new major
// unless we add in the pointless empty methods that are in this class
Deprecation::withNoReplacement(function () {
Deprecation::withSuppressedNotice(function () {
$class = Extension::class;
Deprecation::notice('5.3.0', "Subclass $class instead", Deprecation::SCOPE_CLASS);
});
Expand Down
2 changes: 1 addition & 1 deletion src/ORM/DataObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -1986,7 +1986,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
2 changes: 1 addition & 1 deletion src/ORM/GroupedList.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class GroupedList extends ListDecorator

public function __construct(SS_List&Sortable&Filterable&Limitable $list)
{
Deprecation::withNoReplacement(function () {
Deprecation::withSuppressedNotice(function () {
Deprecation::notice('5.4.0', 'Will be renamed to SilverStripe\Model\List\GroupedList', Deprecation::SCOPE_CLASS);
});
parent::__construct($list);
Expand Down
2 changes: 1 addition & 1 deletion src/ORM/ListDecorator.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ abstract class ListDecorator extends ViewableData implements SS_List, Sortable,
*/
public function __construct(SS_List&Sortable&Filterable&Limitable $list)
{
Deprecation::withNoReplacement(function () {
Deprecation::withSuppressedNotice(function () {
Deprecation::notice('5.4.0', 'Will be renamed to SilverStripe\Model\List\ListDecorator', Deprecation::SCOPE_CLASS);
});

Expand Down
Loading
Loading