Deprecate `Callback` class
authorMatthias Schmidt <gravatronics@live.com>
Sun, 20 Nov 2016 15:10:08 +0000 (16:10 +0100)
committerMatthias Schmidt <gravatronics@live.com>
Sun, 20 Nov 2016 15:10:08 +0000 (16:10 +0100)
Since PHP 5.4, the `callback` type hint is available.

13 files changed:
CHANGELOG.md
wcfsetup/install/files/lib/system/Callback.class.php
wcfsetup/install/files/lib/system/Regex.class.php
wcfsetup/install/files/lib/system/bbcode/highlighter/Highlighter.class.php
wcfsetup/install/files/lib/system/bbcode/highlighter/HtmlHighlighter.class.php
wcfsetup/install/files/lib/system/bbcode/highlighter/SqlHighlighter.class.php
wcfsetup/install/files/lib/system/bbcode/highlighter/XmlHighlighter.class.php
wcfsetup/install/files/lib/system/cache/source/DiskCacheSource.class.php
wcfsetup/install/files/lib/system/package/PackageInstallationNodeBuilder.class.php
wcfsetup/install/files/lib/system/style/StyleCompiler.class.php
wcfsetup/install/files/lib/util/ArrayUtil.class.php
wcfsetup/install/files/lib/util/DirectoryUtil.class.php
wcfsetup/install/files/lib/util/MessageUtil.class.php

index dd60c7a3d6e12e3e7cb96348f447162b3df6b371..8e33fac3e4f374fb77fe15cef51b90e4fca3af6d 100644 (file)
@@ -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.
 
 * Object type definition `com.woltlab.wcf.user.online.location` deprecated.
 * Object type definition `com.woltlab.wcf.page` deprecated.
+* `\wcf\system\Callback` deprecated.
 
 #### Removed Code
 
index 46ec27a994be04df0b0f2294787952e1ecc8d0f8..366ec00b664d4d9955cada462d0b5bf3313b8f7a 100644 (file)
@@ -9,6 +9,7 @@ use wcf\system\exception\SystemException;
  * @copyright  2001-2016 WoltLab GmbH
  * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
  * @package    WoltLabSuite\Core\System
+ * @deprecated since 3.0, use callables and `callable` type hint directly
  */
 final class Callback {
        /**
index 86df04f1d08f81532f3251b502f5b6ce31231bfe..e60f1641713869daddbbc0ab3e7210d80fbb71bb 100644 (file)
@@ -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');
                }
                
index 62278a5747797ed506f7137b7c0698adf416714f..8d3f4866b220c29eeab9267c5ef6e0c93aa98f22 100644 (file)
@@ -1,6 +1,5 @@
 <?php
 namespace wcf\system\bbcode\highlighter;
-use wcf\system\Callback;
 use wcf\system\Regex;
 use wcf\system\SingletonFactory;
 use wcf\system\WCF;
@@ -229,7 +228,7 @@ abstract class Highlighter extends SingletonFactory {
         */
        protected function cacheComments($string) {
                if ($this->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('<span class="hlQuotes">'.StringUtil::encodeHTML($matches[0]).'</span>', 'highlighterQuotes');
-                       }));
+                       });
                }
                
                return $string;
index f5355fc000bdb3bee436a23edbcff9bdd1b7ef97..b296070af44a7462e60391a716f5317ee9a106d6 100644 (file)
@@ -1,6 +1,5 @@
 <?php
 namespace wcf\system\bbcode\highlighter;
-use wcf\system\Callback;
 use wcf\system\Regex;
 use wcf\util\StringStack;
 use wcf\util\StringUtil;
@@ -33,7 +32,7 @@ class HtmlHighlighter extends XmlHighlighter {
        protected function cacheScriptsAndStyles($string) {
                $regex = new Regex('(<(style|script)[^>]*>)(.*?)(</\\2>)', 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('<span class="'.$type.'Highlighter">'.$class::getInstance()->highlight($content).'</span>', 'htmlHighlighter'.ucfirst($type)).$closingTag;
-               }));
+               });
        }
        
        /**
index 68bda16bf279b1b6f4f436c17f60645e629bd0b5..22e3d70e591ebec0d05c72961ee6fa891c738ad6 100644 (file)
@@ -1,6 +1,5 @@
 <?php
 namespace wcf\system\bbcode\highlighter;
-use wcf\system\Callback;
 use wcf\util\StringStack;
 use wcf\util\StringUtil;
 
@@ -43,7 +42,7 @@ class SqlHighlighter extends Highlighter {
         */
        protected function cacheComments($string) {
                if ($this->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('<span class="hlQuotes">'.StringUtil::encodeHTML($matches[0]).'</span>', 'highlighterQuotes', "\0\0");
-                       }));
+                       });
                }
                
                return $string;
index 3bf3714f8d7ac8fb7295e96dd57198599e3bae5d..0bbe6f52b294ca1ceedd3705c709246c9c804b0d 100644 (file)
@@ -1,6 +1,5 @@
 <?php
 namespace wcf\system\bbcode\highlighter;
-use wcf\system\Callback;
 use wcf\system\Regex;
 use wcf\util\StringStack;
 use wcf\util\StringUtil;
@@ -58,13 +57,13 @@ class XmlHighlighter extends Highlighter {
                $string = parent::highlightKeywords($string);
                // find tags
                $regex = new Regex('&lt;(?:/|\!|\?)?[a-z0-9]+(?:\s+'.self::XML_ATTRIBUTE_NAME.'(?:=[^\s/\?&]+)?)*(?:\s+/|\?)?&gt;', Regex::CASE_INSENSITIVE);
-               $string = $regex->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], '<span class="hlKeywords2">\\0</span>');
                        
                        // highlight tag
                        return '<span class="hlKeywords1">'.$tag.'</span>';
-               }));
+               });
                
                return $string;
        }
@@ -76,9 +75,9 @@ class XmlHighlighter extends Highlighter {
                $string = parent::cacheQuotes($string);
                
                // highlight CDATA-Tags as quotes
-               $string = Regex::compile('<!\[CDATA\[.*?\]\]>', Regex::DOT_ALL)->replace($string, new Callback(function (array $matches) {
+               $string = Regex::compile('<!\[CDATA\[.*?\]\]>', Regex::DOT_ALL)->replace($string, function (array $matches) {
                        return StringStack::pushToStringStack('<span class="hlQuotes">'.StringUtil::encodeHTML($matches[0]).'</span>', 'highlighterQuotes');
-               }));
+               });
                
                return $string;
        }
index 4230b56e035905ceb15617c990f2159e00ee4ac4..8f709af607d2798c1eb2c9cf2f8985d1d58e3ddc 100644 (file)
@@ -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));
        }
        
        /**
index 07aac1c61bafd546510847d14326b6e7e20aa068..7d21ed46ae5c94a320600ddf375b3c6bf39cee74 100644 (file)
@@ -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
index e636f3b61738b122421aa3afb931402eb1611ee1..4188256d98141fad0fe09a1807086ca3cb3c129b 100644 (file)
@@ -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.'"';
index f2babdc9aad4057c5ad79280ff108c746a494770..c1e1fc88486e68b55f50383d46af5449f6403b19 100644 (file)
@@ -1,7 +1,6 @@
 <?php
 namespace wcf\util;
 use wcf\system\exception\SystemException;
-use wcf\system\Callback;
 
 /**
  * Contains Array-related functions.
@@ -149,7 +148,7 @@ final class ArrayUtil {
         * @param       callable        $callback
         * @return      boolean
         */
-       public static function compare(array $array1, array $array2, Callback $callback = null) {
+       public static function compare(array $array1, array $array2, callable $callback = null) {
                return static::compareHelper('value', $array1, $array2, $callback);
        }
        
@@ -161,7 +160,7 @@ final class ArrayUtil {
         * @param       callable        $callback
         * @return      boolean
         */
-       public static function compareKey(array $array1, array $array2, Callback $callback = null) {
+       public static function compareKey(array $array1, array $array2, callable $callback = null) {
                return static::compareHelper('key', $array1, $array2, $callback);
        }
        
@@ -173,7 +172,7 @@ final class ArrayUtil {
         * @param       callable        $callback
         * @return      boolean
         */
-       public static function compareAssoc(array $array1, array $array2, Callback $callback = null) {
+       public static function compareAssoc(array $array1, array $array2, callable $callback = null) {
                return static::compareHelper('assoc', $array1, $array2, $callback);
        }
        
@@ -183,11 +182,11 @@ final class ArrayUtil {
         * @param       string          $method
         * @param       array           $array1
         * @param       array           $array2
-        * @param       Callback        $callback
+        * @param       callable        $callback
         * @return      boolean
         * @throws      SystemException
         */
-       protected static function compareHelper($method, array $array1, array $array2, Callback $callback = null) {
+       protected static function compareHelper($method, array $array1, array $array2, callable $callback = null) {
                // get function name
                $function = null;
                if ($method === 'value') {
index 40c22bd024a17d648dc627ddd6d8c08db5c6609c..7364c316e7cde8e43c0ee9ab74b613b67dae8f16 100644 (file)
@@ -1,7 +1,6 @@
 <?php
 namespace wcf\util;
 use wcf\system\exception\SystemException;
-use wcf\system\Callback;
 use wcf\system\Regex;
 
 /**
@@ -254,11 +253,11 @@ final class DirectoryUtil {
        /**
         * Executes a callback on each file and returns false if callback is invalid.
         * 
-        * @param       Callback        $callback
+        * @param       callable        $callback
         * @param       Regex           $pattern        callback is only applied to files matching the given pattern
         * @return      boolean
         */
-       public function executeCallback(Callback $callback, Regex $pattern = null) {
+       public function executeCallback(callable $callback, Regex $pattern = null) {
                if ($pattern !== null) $files = $this->getFileObjects(self::SORT_NONE, $pattern);
                else $files = $this->getFileObjects(self::SORT_NONE);
                
index 5a969acf0f7e81254ee3324596259f9aac12e29e..aaf3613edce9f7dc9fc1346ad3ca1d241115db7f 100644 (file)
@@ -1,7 +1,6 @@
 <?php
 namespace wcf\util;
 use wcf\system\html\input\HtmlInputProcessor;
-use wcf\system\Callback;
 use wcf\system\Regex;
 
 /**
@@ -24,9 +23,9 @@ class MessageUtil {
                $text = Regex::compile('(?<=\?|&)([st]=[a-f0-9]{40}|at=\d+-[a-f0-9]{40})')->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);