Commit | Line | Data |
---|---|---|
c19ff714 | 1 | <?php |
308c880f | 2 | declare(strict_types=1); |
c19ff714 TD |
3 | namespace wcf\system; |
4 | use wcf\system\exception\SystemException; | |
5 | ||
6 | /** | |
7 | * Represents a callback | |
8 | * | |
7405c637 | 9 | * @author Tim Duesterhus |
c839bd49 | 10 | * @copyright 2001-2018 WoltLab GmbH |
c19ff714 | 11 | * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php> |
e71525e4 | 12 | * @package WoltLabSuite\Core\System |
a0c6927a | 13 | * @deprecated since 3.0, use callables and `callable` type hint directly |
c19ff714 TD |
14 | */ |
15 | final class Callback { | |
16 | /** | |
a17de04e | 17 | * encapsulated callback |
c19ff714 TD |
18 | * @var callback |
19 | */ | |
20 | private $callback = null; | |
21 | ||
22 | /** | |
a17de04e MS |
23 | * Creates new instance of Callback. |
24 | * | |
c19ff714 | 25 | * @param callback $callback |
2b770bdd | 26 | * @throws SystemException |
c19ff714 TD |
27 | */ |
28 | public function __construct($callback) { | |
29 | if (!is_callable($callback)) { | |
30 | throw new SystemException('Given callback is not callable.'); | |
31 | } | |
32 | ||
33 | $this->callback = $callback; | |
34 | } | |
35 | ||
36 | /** | |
37 | * Invokes our callback. All parameters are simply passed through. | |
a17de04e MS |
38 | * |
39 | * @return mixed | |
c19ff714 TD |
40 | */ |
41 | public function __invoke() { | |
42 | return call_user_func_array($this->callback, func_get_args()); | |
43 | } | |
44 | } |