Since PHP 5.4, the `callback` type hint is available.
## 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
* @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 {
/**
* 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');
}
<?php
namespace wcf\system\bbcode\highlighter;
-use wcf\system\Callback;
use wcf\system\Regex;
use wcf\system\SingletonFactory;
use wcf\system\WCF;
*/
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 = '';
}
return $string.$hash;
- }));
+ });
}
return $string;
*/
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;
<?php
namespace wcf\system\bbcode\highlighter;
-use wcf\system\Callback;
use wcf\system\Regex;
use wcf\util\StringStack;
use wcf\util\StringUtil;
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
/** @noinspection PhpUndefinedMethodInspection */
return $openingTag.StringStack::pushToStringStack('<span class="'.$type.'Highlighter">'.$class::getInstance()->highlight($content).'</span>', 'htmlHighlighter'.ucfirst($type)).$closingTag;
- }));
+ });
}
/**
<?php
namespace wcf\system\bbcode\highlighter;
-use wcf\system\Callback;
use wcf\util\StringStack;
use wcf\util\StringUtil;
*/
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 = '';
}
return $string.$hash;
- }));
+ });
}
return $string;
*/
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;
<?php
namespace wcf\system\bbcode\highlighter;
-use wcf\system\Callback;
use wcf\system\Regex;
use wcf\util\StringStack;
use wcf\util\StringUtil;
$string = parent::highlightKeywords($string);
// find tags
$regex = new Regex('<(?:/|\!|\?)?[a-z0-9]+(?:\s+'.self::XML_ATTRIBUTE_NAME.'(?:=[^\s/\?&]+)?)*(?:\s+/|\?)?>', 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;
}
$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;
}
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;
$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));
}
/**
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;
* 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
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;
$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;
- })
+ }
);
}
$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;
- })
+ }
);
}
* @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.'"';
<?php
namespace wcf\util;
use wcf\system\exception\SystemException;
-use wcf\system\Callback;
/**
* Contains Array-related functions.
* @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);
}
* @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);
}
* @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);
}
* @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') {
<?php
namespace wcf\util;
use wcf\system\exception\SystemException;
-use wcf\system\Callback;
use wcf\system\Regex;
/**
/**
* 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);
<?php
namespace wcf\util;
use wcf\system\html\input\HtmlInputProcessor;
-use wcf\system\Callback;
use wcf\system\Regex;
/**
$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);