<?php
/**
* Handles adding and dispatching events
*
* @package Requests\EventDispatcher
*/
namespace WpOrg\Requests;
use WpOrg\Requests\Exception\InvalidArgument;
use WpOrg\Requests\HookManager;
use WpOrg\Requests\Utility\InputValidator;
/**
* Handles adding and dispatching events
*
* @package Requests\EventDispatcher
*/
class Hooks implements HookManager {
/**
* Registered callbacks for each hook
*
* @var array
*/
protected $hooks = [];
/**
* Register a callback for a hook
*
* @param string $hook Hook name
* @param callable $callback Function/method to call on event
* @param int $priority Priority number. <0 is executed earlier, >0 is executed later
* @throws \WpOrg\Requests\Exception\InvalidArgument When the passed $hook argument is not a string.
* @throws \WpOrg\Requests\Exception\InvalidArgument When the passed $callback argument is not callable.
* @throws \WpOrg\Requests\Exception\InvalidArgument When the passed $priority argument is not an integer.
*/
public function register($hook, $callback, $priority = 0) {
if (is_string($hook) === false) {
throw InvalidArgument::create(1, '$hook', 'string', gettype($hook));
}
if (is_callable($callback) === false) {
throw InvalidArgument::create(2, '$callback', 'callable', gettype($callback));
}
if (InputValidator::is_numeric_array_key($priority) === false) {
throw InvalidArgument::create(3, '$priority', 'integer', gettype($priority));
}
if (!isset($this->hooks[$hook])) {
$this->hooks[$hook] = [
$priority => [],
];
} elseif (!isset($this->hooks[$hook][$priority])) {
$this->hooks[$hook][$priority] = [];
}
$this->hooks[$hook][$priority][] = $callback;
}
/**
* Dispatch a message
*
* @param string $hook Hook name
* @param array $parameters Parameters to pass to callbacks
* @return boolean Successfulness
* @throws \WpOrg\Requests\Exception\InvalidArgument When the passed $hook argument is not a string.
* @throws \WpOrg\Requests\Exception\InvalidArgument When the passed $parameters argument is not an array.
*/
public function dispatch($hook, $parameters = []) {
if (is_string($hook) === false) {
throw InvalidArgument::create(1, '$hook', 'string', gettype($hook));
}
// Check strictly against array, as Array* objects don't work in combination with `call_user_func_array()`.
if (is_array($parameters) === false) {
throw InvalidArgument::create(2, '$parameters', 'array', gettype($parameters));
}
if (empty($this->hooks[$hook])) {
return false;
}
if (!empty($parameters)) {
// Strip potential keys from the array to prevent them being interpreted as parameter names in PHP 8.0.
$parameters = array_values($parameters);
}
ksort($this->hooks[$hook]);
foreach ($this->hooks[$hook] as $priority => $hooked) {
foreach ($hooked as $callback) {
$callback(...$parameters);
}
}
return true;
}
public function __wakeup() {
throw new \LogicException( __CLASS__ . ' should never be unserialized' );
}
}
| nama | waktu | ukuran | owner | perm | aksi |
|---|---|---|---|---|---|
| .. | |||||
| Auth/ | 2023-07-04 19:03 | 2.48 KB | 76129f60960:kunden | dxwrx-rx-r | |
| Cookie/ | 2023-07-04 19:03 | 4.26 KB | 76129f60960:kunden | dxwrx-rx-r | |
| Exception/ | 2023-07-04 19:03 | 21.94 KB | 76129f60960:kunden | dxwrx-rx-r | |
| Proxy/ | 2023-07-04 19:03 | 4.12 KB | 76129f60960:kunden | dxwrx-rx-r | |
| Response/ | 2023-07-04 19:03 | 3.04 KB | 76129f60960:kunden | dxwrx-rx-r | |
| Transport/ | 2023-07-04 19:03 | 35.11 KB | 76129f60960:kunden | dxwrx-rx-r | |
| Utility/ | 2023-07-04 19:03 | 7.17 KB | 76129f60960:kunden | dxwrx-rx-r | |
| Auth.php | 2023-07-04 19:03 | 860 B | 76129f60960:kunden | -xw-x----- | |
| Autoload.php | 2023-09-21 23:24 | 9.12 KB | 76129f60960:kunden | -xw-x----- | |
| Capability.php | 2023-09-21 23:24 | 652 B | 76129f60960:kunden | -xw-x----- | |
| Cookie.php | 2024-08-09 01:01 | 15.03 KB | 76129f60960:kunden | -xw-x----- | |
| Exception.php | 2023-07-04 19:03 | 1.09 KB | 76129f60960:kunden | -xw-x----- | |
| HookManager.php | 2023-07-04 19:03 | 709 B | 76129f60960:kunden | -xw-x----- | |
| Hooks.php | 2024-01-20 23:47 | 2.96 KB | 76129f60960:kunden | -xw-x----- | |
| IdnaEncoder.php | 2026-10-22 10:47 | 12.16 KB | 76129f60960:kunden | -xw-x--x-- | |
| Ipv6.php | 2026-10-22 10:47 | 5.51 KB | 76129f60960:kunden | -xw-x--x-- | |
| Iri.php | 2026-10-22 10:47 | 29.03 KB | 76129f60960:kunden | -xw-x--x-- | |
| Port.php | 2023-07-04 19:03 | 1.47 KB | 76129f60960:kunden | -xw-x----- | |
| Proxy.php | 2023-07-04 19:03 | 867 B | 76129f60960:kunden | -xw-x----- | |
| Requests.php | 2026-10-22 10:47 | 33.2 KB | 76129f60960:kunden | -xw-x--x-- | |
| Response.php | 2023-09-21 23:24 | 4.18 KB | 76129f60960:kunden | -xw-x----- | |
| Session.php | 2024-01-20 23:47 | 8.89 KB | 76129f60960:kunden | -xw-x----- | |
| Ssl.php | 2023-07-04 19:03 | 5.3 KB | 76129f60960:kunden | -xw-x----- | |
| Transport.php | 2023-07-04 19:03 | 1.51 KB | 76129f60960:kunden | -xw-x----- | |