From a0c6927a362a091ba557c11bb5579956e79a95d8 Mon Sep 17 00:00:00 2001 From: Matthias Schmidt Date: Sun, 20 Nov 2016 16:10:08 +0100 Subject: [PATCH] Deprecate `Callback` class Since PHP 5.4, the `callback` type hint is available. --- CHANGELOG.md | 3 ++- .../install/files/lib/system/Callback.class.php | 1 + wcfsetup/install/files/lib/system/Regex.class.php | 4 ++-- .../system/bbcode/highlighter/Highlighter.class.php | 9 ++++----- .../bbcode/highlighter/HtmlHighlighter.class.php | 5 ++--- .../bbcode/highlighter/SqlHighlighter.class.php | 9 ++++----- .../bbcode/highlighter/XmlHighlighter.class.php | 9 ++++----- .../system/cache/source/DiskCacheSource.class.php | 5 ++--- .../PackageInstallationNodeBuilder.class.php | 5 ++--- .../files/lib/system/style/StyleCompiler.class.php | 13 ++++++------- wcfsetup/install/files/lib/util/ArrayUtil.class.php | 11 +++++------ .../install/files/lib/util/DirectoryUtil.class.php | 5 ++--- .../install/files/lib/util/MessageUtil.class.php | 5 ++--- 13 files changed, 38 insertions(+), 46 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dd60c7a3d6..8e33fac3e4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## 3.0 (Vortex) -### 3.0.0 Alpha 1 (XXXX-YY-ZZ) +### 3.0.0 (XXXX-YY-ZZ) * Clipboard support for tags in ACP ("delete" and "set as synonyms"). * `wcf\system\cache\runtime\UserProfileRuntimeCache` for caching user profiles during runtime. @@ -131,6 +131,7 @@ * Object type definition `com.woltlab.wcf.user.online.location` deprecated. * Object type definition `com.woltlab.wcf.page` deprecated. +* `\wcf\system\Callback` deprecated. #### Removed Code diff --git a/wcfsetup/install/files/lib/system/Callback.class.php b/wcfsetup/install/files/lib/system/Callback.class.php index 46ec27a994..366ec00b66 100644 --- a/wcfsetup/install/files/lib/system/Callback.class.php +++ b/wcfsetup/install/files/lib/system/Callback.class.php @@ -9,6 +9,7 @@ use wcf\system\exception\SystemException; * @copyright 2001-2016 WoltLab GmbH * @license GNU Lesser General Public License * @package WoltLabSuite\Core\System + * @deprecated since 3.0, use callables and `callable` type hint directly */ final class Callback { /** diff --git a/wcfsetup/install/files/lib/system/Regex.class.php b/wcfsetup/install/files/lib/system/Regex.class.php index 86df04f1d0..e60f164171 100644 --- a/wcfsetup/install/files/lib/system/Regex.class.php +++ b/wcfsetup/install/files/lib/system/Regex.class.php @@ -201,11 +201,11 @@ final class Regex { * Replaces part of the string with the regex. * * @param string $string - * @param mixed $replacement replacement-string or instance of wcf\system\Callback + * @param mixed $replacement replacement-string or callable * @return string */ public function replace($string, $replacement) { - if ($replacement instanceof Callback) { + if ($replacement instanceof Callback || $replacement instanceof \Closure) { return $this->checkResult(preg_replace_callback($this->regex, $replacement, $string), 'replace'); } diff --git a/wcfsetup/install/files/lib/system/bbcode/highlighter/Highlighter.class.php b/wcfsetup/install/files/lib/system/bbcode/highlighter/Highlighter.class.php index 62278a5747..8d3f4866b2 100644 --- a/wcfsetup/install/files/lib/system/bbcode/highlighter/Highlighter.class.php +++ b/wcfsetup/install/files/lib/system/bbcode/highlighter/Highlighter.class.php @@ -1,6 +1,5 @@ cacheCommentsRegEx !== null) { - $string = $this->cacheCommentsRegEx->replace($string, new Callback(function (array $matches) { + $string = $this->cacheCommentsRegEx->replace($string, function (array $matches) { $string = $matches[1]; if (isset($matches[2])) $comment = $matches[2]; else $comment = ''; @@ -241,7 +240,7 @@ abstract class Highlighter extends SingletonFactory { } return $string.$hash; - })); + }); } return $string; @@ -255,9 +254,9 @@ abstract class Highlighter extends SingletonFactory { */ protected function cacheQuotes($string) { if ($this->quotesRegEx !== null) { - $string = $this->quotesRegEx->replace($string, new Callback(function (array $matches) { + $string = $this->quotesRegEx->replace($string, function (array $matches) { return StringStack::pushToStringStack(''.StringUtil::encodeHTML($matches[0]).'', 'highlighterQuotes'); - })); + }); } return $string; diff --git a/wcfsetup/install/files/lib/system/bbcode/highlighter/HtmlHighlighter.class.php b/wcfsetup/install/files/lib/system/bbcode/highlighter/HtmlHighlighter.class.php index f5355fc000..b296070af4 100644 --- a/wcfsetup/install/files/lib/system/bbcode/highlighter/HtmlHighlighter.class.php +++ b/wcfsetup/install/files/lib/system/bbcode/highlighter/HtmlHighlighter.class.php @@ -1,6 +1,5 @@ ]*>)(.*?)()', Regex::CASE_INSENSITIVE | Regex::DOT_ALL); - return $regex->replace($string, new Callback(function ($matches) { + return $regex->replace($string, function ($matches) { $type = ($matches[2] === 'script') ? 'js' : 'css'; // strip slashes @@ -47,7 +46,7 @@ class HtmlHighlighter extends XmlHighlighter { /** @noinspection PhpUndefinedMethodInspection */ return $openingTag.StringStack::pushToStringStack(''.$class::getInstance()->highlight($content).'', 'htmlHighlighter'.ucfirst($type)).$closingTag; - })); + }); } /** diff --git a/wcfsetup/install/files/lib/system/bbcode/highlighter/SqlHighlighter.class.php b/wcfsetup/install/files/lib/system/bbcode/highlighter/SqlHighlighter.class.php index 68bda16bf2..22e3d70e59 100644 --- a/wcfsetup/install/files/lib/system/bbcode/highlighter/SqlHighlighter.class.php +++ b/wcfsetup/install/files/lib/system/bbcode/highlighter/SqlHighlighter.class.php @@ -1,6 +1,5 @@ cacheCommentsRegEx !== null) { - $string = $this->cacheCommentsRegEx->replace($string, new Callback(function (array $matches) { + $string = $this->cacheCommentsRegEx->replace($string, function (array $matches) { $string = $matches[1]; if (isset($matches[2])) $comment = $matches[2]; else $comment = ''; @@ -59,7 +58,7 @@ class SqlHighlighter extends Highlighter { } return $string.$hash; - })); + }); } return $string; @@ -70,9 +69,9 @@ class SqlHighlighter extends Highlighter { */ protected function cacheQuotes($string) { if ($this->quotesRegEx !== null) { - $string = $this->quotesRegEx->replace($string, new Callback(function (array $matches) { + $string = $this->quotesRegEx->replace($string, function (array $matches) { return StringStack::pushToStringStack(''.StringUtil::encodeHTML($matches[0]).'', 'highlighterQuotes', "\0\0"); - })); + }); } return $string; diff --git a/wcfsetup/install/files/lib/system/bbcode/highlighter/XmlHighlighter.class.php b/wcfsetup/install/files/lib/system/bbcode/highlighter/XmlHighlighter.class.php index 3bf3714f8d..0bbe6f52b2 100644 --- a/wcfsetup/install/files/lib/system/bbcode/highlighter/XmlHighlighter.class.php +++ b/wcfsetup/install/files/lib/system/bbcode/highlighter/XmlHighlighter.class.php @@ -1,6 +1,5 @@ replace($string, new Callback(function ($matches) { + $string = $regex->replace($string, function ($matches) { // highlight attributes $tag = Regex::compile(XmlHighlighter::XML_ATTRIBUTE_NAME.'(?:=[^\s/\?&]+)?(?=\s|&)', Regex::CASE_INSENSITIVE)->replace($matches[0], '\\0'); // highlight tag return ''.$tag.''; - })); + }); return $string; } @@ -76,9 +75,9 @@ class XmlHighlighter extends Highlighter { $string = parent::cacheQuotes($string); // highlight CDATA-Tags as quotes - $string = Regex::compile('', Regex::DOT_ALL)->replace($string, new Callback(function (array $matches) { + $string = Regex::compile('', Regex::DOT_ALL)->replace($string, function (array $matches) { return StringStack::pushToStringStack(''.StringUtil::encodeHTML($matches[0]).'', 'highlighterQuotes'); - })); + }); return $string; } diff --git a/wcfsetup/install/files/lib/system/cache/source/DiskCacheSource.class.php b/wcfsetup/install/files/lib/system/cache/source/DiskCacheSource.class.php index 4230b56e03..8f709af607 100644 --- a/wcfsetup/install/files/lib/system/cache/source/DiskCacheSource.class.php +++ b/wcfsetup/install/files/lib/system/cache/source/DiskCacheSource.class.php @@ -2,7 +2,6 @@ namespace wcf\system\cache\source; use wcf\system\exception\SystemException; use wcf\system\io\AtomicWriter; -use wcf\system\Callback; use wcf\system\Regex; use wcf\system\WCF; use wcf\util\DirectoryUtil; @@ -98,13 +97,13 @@ class DiskCacheSource implements ICacheSource { $directory = FileUtil::unifyDirSeparator(WCF_DIR.'cache/'); $pattern = str_replace('*', '.*', str_replace('.', '\.', $pattern)); - $this->getDirectoryUtil()->executeCallback(new Callback(function ($filename) { + $this->getDirectoryUtil()->executeCallback(function ($filename) { if (!@touch($filename, 1)) { @unlink($filename); WCF::resetZendOpcache($filename); } - }), new Regex('^'.$directory.$pattern.'$', Regex::CASE_INSENSITIVE)); + }, new Regex('^'.$directory.$pattern.'$', Regex::CASE_INSENSITIVE)); } /** diff --git a/wcfsetup/install/files/lib/system/package/PackageInstallationNodeBuilder.class.php b/wcfsetup/install/files/lib/system/package/PackageInstallationNodeBuilder.class.php index 07aac1c61b..7d21ed46ae 100644 --- a/wcfsetup/install/files/lib/system/package/PackageInstallationNodeBuilder.class.php +++ b/wcfsetup/install/files/lib/system/package/PackageInstallationNodeBuilder.class.php @@ -4,7 +4,6 @@ use wcf\data\package\installation\queue\PackageInstallationQueueEditor; use wcf\data\package\installation\queue\PackageInstallationQueueList; use wcf\data\package\Package; use wcf\system\exception\SystemException; -use wcf\system\Callback; use wcf\system\WCF; use wcf\util\FileUtil; use wcf\util\StringUtil; @@ -346,9 +345,9 @@ class PackageInstallationNodeBuilder { * to insert more than a single node, you should prefer shiftNodes(). * * @param string $beforeNode - * @param Callback $callback + * @param callable $callback */ - public function insertNode($beforeNode, Callback $callback) { + public function insertNode($beforeNode, callable $callback) { $newNode = $this->getToken(); // update descendants diff --git a/wcfsetup/install/files/lib/system/style/StyleCompiler.class.php b/wcfsetup/install/files/lib/system/style/StyleCompiler.class.php index e636f3b617..4188256d98 100644 --- a/wcfsetup/install/files/lib/system/style/StyleCompiler.class.php +++ b/wcfsetup/install/files/lib/system/style/StyleCompiler.class.php @@ -5,7 +5,6 @@ use wcf\data\application\Application; use wcf\data\option\Option; use wcf\data\style\Style; use wcf\system\exception\SystemException; -use wcf\system\Callback; use wcf\system\SingletonFactory; use wcf\system\WCF; use wcf\util\FileUtil; @@ -97,9 +96,9 @@ class StyleCompiler extends SingletonFactory { $files, $variables, $individualScss, - new Callback(function($content) use ($style) { + function($content) use ($style) { return "/* stylesheet for '".$style->styleName."', generated on ".gmdate('r')." -- DO NOT EDIT */\n\n" . $content; - }) + } ); } @@ -145,14 +144,14 @@ class StyleCompiler extends SingletonFactory { $files, $variables, '', - new Callback(function($content) { + function($content) { // fix relative paths $content = str_replace('../font/', '../../font/', $content); $content = str_replace('../icon/', '../../icon/', $content); $content = preg_replace('~\.\./images/~', '../../images/', $content); return "/* stylesheet for ACP, generated on ".gmdate('r')." -- DO NOT EDIT */\n\n" . $content; - }) + } ); } @@ -240,10 +239,10 @@ class StyleCompiler extends SingletonFactory { * @param string[] $files * @param string[] $variables * @param string $individualScss - * @param Callback $callback + * @param callable $callback * @throws SystemException */ - protected function compileStylesheet($filename, array $files, array $variables, $individualScss, Callback $callback) { + protected function compileStylesheet($filename, array $files, array $variables, $individualScss, callable $callback) { foreach ($variables as &$value) { if (StringUtil::startsWith($value, '../')) { $value = '~"'.$value.'"'; diff --git a/wcfsetup/install/files/lib/util/ArrayUtil.class.php b/wcfsetup/install/files/lib/util/ArrayUtil.class.php index f2babdc9aa..c1e1fc8848 100644 --- a/wcfsetup/install/files/lib/util/ArrayUtil.class.php +++ b/wcfsetup/install/files/lib/util/ArrayUtil.class.php @@ -1,7 +1,6 @@ getFileObjects(self::SORT_NONE, $pattern); else $files = $this->getFileObjects(self::SORT_NONE); diff --git a/wcfsetup/install/files/lib/util/MessageUtil.class.php b/wcfsetup/install/files/lib/util/MessageUtil.class.php index 5a969acf0f..aaf3613edc 100644 --- a/wcfsetup/install/files/lib/util/MessageUtil.class.php +++ b/wcfsetup/install/files/lib/util/MessageUtil.class.php @@ -1,7 +1,6 @@ replace($text, ''); // convert html entities (utf-8) - $text = Regex::compile('&#(3[2-9]|[4-9][0-9]|\d{3,5});')->replace($text, new Callback(function ($matches) { + $text = Regex::compile('&#(3[2-9]|[4-9][0-9]|\d{3,5});')->replace($text, function ($matches) { return StringUtil::getCharacter(intval($matches[1])); - })); + }); // unify new lines $text = StringUtil::unifyNewlines($text); -- 2.20.1