You can use wcf\system\Callback as typehint if you want to force a callable function as parameter.
--- /dev/null
+<?php
+namespace wcf\system;
+use wcf\system\exception\SystemException;
+
+/**
+ * Represents a callback
+ *
+ * @author Tim Düsterhus
+ * @copyright 2011 Tim Düsterhus
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package com.woltlab.wcf
+ * @subpackage system
+ * @category Community Framework
+ */
+final class Callback {
+ /**
+ * The callback
+ *
+ * @var callback
+ */
+ private $callback = null;
+
+ /**
+ * Checks whether the callback is callable.
+ *
+ * @param callback $callback
+ */
+ public function __construct($callback) {
+ if (!is_callable($callback)) {
+ throw new SystemException('Given callback is not callable.');
+ }
+
+ $this->callback = $callback;
+ }
+
+ /**
+ * Invokes our callback. All parameters are simply passed through.
+ *
+ * @return mixed
+ */
+ public function __invoke() {
+ return call_user_func_array($this->callback, func_get_args());
+ }
+}
namespace wcf\system\package;
use wcf\data\package\installation\queue\PackageInstallationQueue;
use wcf\data\package\installation\queue\PackageInstallationQueueEditor;
+use wcf\system\Callback;
use wcf\system\WCF;
use wcf\util\FileUtil;
use wcf\util\StringUtil;
* nodes to provide to be descendants of the new node. If you intend
* to insert more than a single node, you should prefer shiftNodes().
*
- * @param string $beforeNode
- * @param function $callback
+ * @param string $beforeNode
+ * @param wcf\system\Callback $callback
*/
- public function insertNode($beforeNode, $callback) {
- // verify if callback is a valid function
- if (!is_callable($callback)) {
- throw new SystemException("Provided callback is not a callable function.");
- }
-
+ public function insertNode($beforeNode, Callback $callback) {
$newNode = $this->getToken();
// update descendants
<?php
namespace wcf\util;
+use wcf\system\Callback;
use wcf\system\exception\SystemException;
/**
-* Contains directory-related functions
-*
-* @author Tim Düsterhus
-* @copyright 2011 Tim Düsterhus
-* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
-* @package com.woltlab.wcf
-* @subpackage util
-* @category Community Framework
-*/
+ * Contains directory-related functions
+ *
+ * @author Tim Düsterhus
+ * @copyright 2011 Tim Düsterhus
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package com.woltlab.wcf
+ * @subpackage util
+ * @category Community Framework
+ */
class DirectoryUtil {
/**
* @var \DirectoryIterator
/**
* Executes a callback on each file and returns false if callback is invalid.
*
- * @param callback $callback valid callback
- * @param string $pattern callback is only applied to files matching the given pattern
+ * @param wcf\system\Callback $callback
+ * @param string $pattern callback is only applied to files matching the given pattern
* @return boolean
*/
- public function executeCallback($callback, $pattern = '') {
- if (!is_callable($callback)) return false;
-
+ public function executeCallback(Callback $callback, $pattern = '') {
$files = $this->getFileObjects(self::SORT_NONE, $pattern);
foreach ($files as $filename => $obj) {
- call_user_func($callback, $filename, $obj);
+ $callback($filename, $obj);
}
return true;