Make WordPress Core


Ignore:
Timestamp:
12/06/2021 09:29:00 PM (3 years ago)
Author:
SergeyBiryukov
Message:

HTTP API: Revert changeset [52244].

Reverting Requests 2.0.0 changes and moving to WordPress 6.0 cycle. Why? The namespace and file case renaming revealed 2 issues in Core's upgrader process.

See https://core.trac.wordpress.org/ticket/54504#comment:22 for more information.

Follow-up to [52327].

See #54562, #54504.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/Requests/Hooks.php

    r52244 r52328  
    33 * Handles adding and dispatching events
    44 *
    5  * @package Requests\EventDispatcher
     5 * @package Requests
     6 * @subpackage Utilities
    67 */
    7 
    8 namespace WpOrg\Requests;
    9 
    10 use WpOrg\Requests\Exception\InvalidArgument;
    11 use WpOrg\Requests\HookManager;
    12 use WpOrg\Requests\Utility\InputValidator;
    138
    149/**
    1510 * Handles adding and dispatching events
    1611 *
    17  * @package Requests\EventDispatcher
     12 * @package Requests
     13 * @subpackage Utilities
    1814 */
    19 class Hooks implements HookManager {
     15class Requests_Hooks implements Requests_Hooker {
    2016    /**
    2117     * Registered callbacks for each hook
     
    2319     * @var array
    2420     */
    25     protected $hooks = [];
     21    protected $hooks = array();
     22
     23    /**
     24     * Constructor
     25     */
     26    public function __construct() {
     27        // pass
     28    }
    2629
    2730    /**
     
    2932     *
    3033     * @param string $hook Hook name
    31      * @param callable $callback Function/method to call on event
     34     * @param callback $callback Function/method to call on event
    3235     * @param int $priority Priority number. <0 is executed earlier, >0 is executed later
    33      * @throws \WpOrg\Requests\Exception\InvalidArgument When the passed $hook argument is not a string.
    34      * @throws \WpOrg\Requests\Exception\InvalidArgument When the passed $callback argument is not callable.
    35      * @throws \WpOrg\Requests\Exception\InvalidArgument When the passed $priority argument is not an integer.
    3636     */
    3737    public function register($hook, $callback, $priority = 0) {
    38         if (is_string($hook) === false) {
    39             throw InvalidArgument::create(1, '$hook', 'string', gettype($hook));
     38        if (!isset($this->hooks[$hook])) {
     39            $this->hooks[$hook] = array();
    4040        }
    41 
    42         if (is_callable($callback) === false) {
    43             throw InvalidArgument::create(2, '$callback', 'callable', gettype($callback));
    44         }
    45 
    46         if (InputValidator::is_numeric_array_key($priority) === false) {
    47             throw InvalidArgument::create(3, '$priority', 'integer', gettype($priority));
    48         }
    49 
    50         if (!isset($this->hooks[$hook])) {
    51             $this->hooks[$hook] = [
    52                 $priority => [],
    53             ];
    54         } elseif (!isset($this->hooks[$hook][$priority])) {
    55             $this->hooks[$hook][$priority] = [];
     41        if (!isset($this->hooks[$hook][$priority])) {
     42            $this->hooks[$hook][$priority] = array();
    5643        }
    5744
     
    6552     * @param array $parameters Parameters to pass to callbacks
    6653     * @return boolean Successfulness
    67      * @throws \WpOrg\Requests\Exception\InvalidArgument When the passed $hook argument is not a string.
    68      * @throws \WpOrg\Requests\Exception\InvalidArgument When the passed $parameters argument is not an array.
    6954     */
    70     public function dispatch($hook, $parameters = []) {
    71         if (is_string($hook) === false) {
    72             throw InvalidArgument::create(1, '$hook', 'string', gettype($hook));
    73         }
    74 
    75         // Check strictly against array, as Array* objects don't work in combination with `call_user_func_array()`.
    76         if (is_array($parameters) === false) {
    77             throw InvalidArgument::create(2, '$parameters', 'array', gettype($parameters));
    78         }
    79 
     55    public function dispatch($hook, $parameters = array()) {
    8056        if (empty($this->hooks[$hook])) {
    8157            return false;
    8258        }
    8359
    84         if (!empty($parameters)) {
    85             // Strip potential keys from the array to prevent them being interpreted as parameter names in PHP 8.0.
    86             $parameters = array_values($parameters);
    87         }
    88 
    8960        foreach ($this->hooks[$hook] as $priority => $hooked) {
    9061            foreach ($hooked as $callback) {
    91                 $callback(...$parameters);
     62                call_user_func_array($callback, $parameters);
    9263            }
    9364        }
Note: See TracChangeset for help on using the changeset viewer.