-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add namespace deprecator * docs: fix typo in ci * refactor: change namespace BracketSpace\Notification\Defaults to BracketSpace\Notification\Repository * fix: change adapter namespace * fix: compat namespace * fix: phpstan * fix: phpstan * fix: autoloader exclusion * fix: autoloader exclusion * fix: phpstan
- Loading branch information
1 parent
438628e
commit 9964f0b
Showing
161 changed files
with
632 additions
and
584 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
/** | ||
* Deprecation helpers | ||
* | ||
* @package notification | ||
*/ | ||
|
||
/** | ||
* Helper function. | ||
* Throws a deprecation notice from deprecated class | ||
* | ||
* @since 6.0.0 | ||
* @param string $class Deprecated class name. | ||
* @param string $version Version since deprecated. | ||
* @param string $replacement Replacement class. | ||
* @return void | ||
*/ | ||
function notification_deprecated_class($class, $version, $replacement = null) { | ||
if (! defined('WP_DEBUG') || ! WP_DEBUG) { | ||
return; | ||
} | ||
|
||
if (function_exists('__')) { | ||
if (! is_null($replacement)) { | ||
/* translators: 1: Class name, 2: version number, 3: alternative function name */ | ||
trigger_error(sprintf(__('Class %1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.'), $class, $version, $replacement), E_USER_DEPRECATED); | ||
} else { | ||
/* translators: 1: Class name, 2: version number */ | ||
trigger_error(sprintf(__('Class %1$s is <strong>deprecated</strong> since version %2$s with no alternative available.'), $class, $version), E_USER_DEPRECATED); | ||
} | ||
} else { | ||
if (! is_null($replacement)) { | ||
trigger_error(sprintf('Class %1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.', $class, $version, $replacement), E_USER_DEPRECATED); | ||
} else { | ||
trigger_error(sprintf('Class %1$s is <strong>deprecated</strong> since version %2$s with no alternative available.', $class, $version), E_USER_DEPRECATED); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
/** | ||
* Deprecated namespaces | ||
* | ||
* @package notification | ||
*/ | ||
|
||
spl_autoload_register(function ($class) { | ||
$deprecations = [ | ||
'[Next]' => [ | ||
'BracketSpace\Notification\Defaults' => 'BracketSpace\Notification\Repository', | ||
], | ||
]; | ||
|
||
// Classes meant to be left as is, ie. deprecated ones. | ||
$exclusions = [ | ||
'BracketSpace\Notification\Defaults\Adapter', | ||
]; | ||
|
||
foreach ($deprecations as $version => $map) { | ||
foreach ($map as $oldNamespace => $newNamespace) { | ||
// Match the loaded classname. | ||
if (strpos($class, $oldNamespace) !== 0) { | ||
continue; | ||
} | ||
|
||
// Check for exclusions. | ||
foreach ($exclusions as $excludedNamespace) { | ||
if (strpos($class, $excludedNamespace) !== 0) { | ||
break 2; | ||
} | ||
} | ||
|
||
$newClass = str_replace($oldNamespace, $newNamespace, $class); | ||
|
||
if (! class_exists($newClass)) { | ||
break; | ||
} | ||
|
||
notification_deprecated_class($class, $version, $newClass); | ||
|
||
class_alias($newClass, $class); | ||
} | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.