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

Change namespace #467

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
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
run: git flow init -d
- name: Start release
run: git flow release start ${{ github.event.inputs.new_version }}
- name: Replace 8.0.0 tags with new version number
- name: Replace Next tags with new version number
uses: jacobtomlinson/gha-find-replace@master
with:
find: "(?i)\\[Next\\]"
Expand Down
34 changes: 0 additions & 34 deletions compat/src-deprecated/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,40 +18,6 @@
use BracketSpace\Notification\Store;
use BracketSpace\Notification\Dependencies\Micropackage\DocHooks\Helper as DocHooksHelper;

/**
* 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 ) {

// phpcs:disable
if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
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 ) );
} 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 ) );
}
} 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 ) );
} else {
trigger_error( sprintf( 'Class %1$s is <strong>deprecated</strong> since version %2$s with no alternative available.', $class, $version ) );
}
}
}
// phpcs:enable

}

/**
* Gets cached value or cache object
*
Expand Down
38 changes: 38 additions & 0 deletions compat/src-deprecated/helpers.php
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);
}
}
}
45 changes: 45 additions & 0 deletions compat/src-deprecated/namespaces.php
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);
}
}
});
2 changes: 2 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
"dependencies/"
],
"files": [
"compat/src-deprecated/helpers.php",
"compat/src-deprecated/namespaces.php",
"compat/src-deprecated/functions.php"
]
},
Expand Down
Loading
Loading