Set a "pre" hook.
@param string   $hookName
@param Callable $cb
@return mixed
161928
public function preHook($hookName, $cb) {
		$args = [$hookName, $cb];
		return call_user_func_array([$this->getHookManager(), 'preHook'], $args);
	}
1019469
public function getHook(string $name): Hook
  {
    # Find hook in list
    foreach ($this->hooks as $hook)
    {
      if (\strcasecmp($name,$hook->getName()==0)) {
        return $hook;
      }
    }

    return null;
  }
556726
protected function callBeforeMethodHooks($classInstance, $method, array $args = [])
    {
        $method = self::getCalledMethod($method);

        $beforeMethodCallableName = 'before'.ucfirst($method);

        $hooks = isset($this->hooks[$beforeMethodCallableName]) ? $this->hooks[$beforeMethodCallableName] : [];

        $staticHooks = isset(self::$staticHooks['global'][$beforeMethodCallableName]) ?
            self::$staticHooks['global'][$beforeMethodCallableName] : [];

        $hooks = array_merge($hooks, $staticHooks);

        if ( ! empty($hooks)) {
            foreach ($hooks as $callable) {
                try {
                    $return = $this->callCallable($classInstance, $callable, $args, $method, false);
                } catch (CancelPropagationException $e) {
                    break;
                }

                if ($return !== null) {
                    return $return;
                }
            }
        }
    }
7370
public static function wrap($cb, $timeout = null, $ctx = false)
    {
        if ($cb instanceof CallbackWrapper || ((Daemon::$context === null) && ($timeout === null))) {
            return $cb;
        }
        if ($cb === null) {
            return null;
        }
        return new static($cb, $timeout, $ctx !== false ? $ctx : Daemon::$context);
    }
620996
public function bind($event, $cb)
    {
        if ($cb !== null) {
            $cb = CallbackWrapper::wrap($cb);
        }
        $event = (array) $event;
        foreach ($event as $e) {
            CallbackWrapper::addToArray($this->eventHandlers[$e], $cb);
        }
        return $this;
    }
7412
public static function hook($hook, $params = [])
    {
        $hookRun = isset(self::$mountInfo[$hook]) ? self::$mountInfo[$hook] : null;
        if (!is_null($hookRun)) {
            foreach ($hookRun as $key => $val) {
                if (is_int($key)) {
                    $callBack = $val;
                } else {
                    $plugin = new $key();
                    $callBack = [$plugin, $val];
                }
                $return = call_user_func_array($callBack, array_slice(func_get_args(), 1));

                if (!is_null($return)) {
                    return $return;
                }
            }
        }
        return null;
    }
323082
public function beforeEach(\Closure $closure)
    {
        $key = 'beforeEach';
        $beforeEach = new Hook($key, $closure, $this->current);
        $this->current->setHook($key, $beforeEach);
    }
1316702
public function exists($hookName, $functionToCheck = false)
    {
        $hookName = $this->sanitizeKeyName($hookName);
        if (! $hookName || ! isset($this->filters[$hookName])) {
            return false;
        }

        // Don't reset the internal array pointer
        $has    = empty($this->filters[$hookName]);
        // Make sure at least one priority has a filter callback
        if ($has) {
            $exists = false;
            foreach ($this->filters[$hookName] as $callbacks) {
                if (! empty($callbacks)) {
                    $exists = true;
                    break;
                }
            }

            if (! $exists) {
                $has = false;
            }
        }

        // recheck
        if ($functionToCheck === false || $has === false) {
            return $has;
        }

        if (! $id = $this->uniqueId($functionToCheck)) {
            return false;
        }

        foreach ($this->filters[$hookName] as $priority) {
            if (isset($priority[$id])) {
                return $priority;
            }
        }

        return false;
    }
732508
protected function callHooks($name)
    {
        $hooks = Arr::get($this->hooks, $name, []);

        foreach ($hooks as $func) {
            if (!$func instanceof Closure) {
                continue;
            }

            $response = call_user_func($func, $this);

            if ($response instanceof Response) {
                return $response;
            }
        }
    }
1324760
public function wp_hook_begin() {

		foreach ( Logger::$active_loggers as $logger ) {
			$logger->start_hook_timer();
		}

		$current_filter = current_filter();
		if ( ( 'stage' === $this->type && in_array( $current_filter, $this->current_stage_hooks ) )
			|| ( 'hook' === $this->type && ! $this->focus ) ) {
			$pseudo_hook = "{$current_filter}:before";
			if ( isset( $this->loggers[ $pseudo_hook ] ) ) {
				$this->loggers[ $pseudo_hook ]->stop();
			}
			$callback_count = 0;
			$callbacks      = self::get_filter_callbacks( $current_filter );
			if ( false !== $callbacks ) {
				foreach ( $callbacks as $priority => $cbs ) {
					$callback_count += count( $cbs );
				}
			}
			$this->loggers[ $current_filter ] = new Logger(
				array(
					'hook'           => $current_filter,
					'callback_count' => $callback_count,
				)
			);
			$this->loggers[ $current_filter ]->start();
		}

		if ( 0 === $this->filter_depth
			&& ! is_null( $this->previous_filter_callbacks ) ) {
			self::set_filter_callbacks( $this->previous_filter, $this->previous_filter_callbacks );
			$this->previous_filter_callbacks = null;
		}

		if ( 'hook' === $this->type
			&& 0 === $this->filter_depth
			&& ( $current_filter === $this->focus || true === $this->focus ) ) {
			$this->wrap_current_filter_callbacks( $current_filter );
		}

		$this->filter_depth++;

		WP_CLI::add_wp_hook( $current_filter, array( $this, 'wp_hook_end' ), 9999 );
	}
566752
public function hook($hookName, $handler = null, $override = false)
    {
        if (is_callable($handler) && is_string($hookName)) {
            if (in_array($hookName, self::$hooks)) {
                if (!isset($this->handlers[$hookName])) {
                    $this->handlers[$hookName] = [];
                }
                if ($override) {
                    $this->handlers[$hookName] = [$handler];
                } else {
                    array_push($this->handlers[$hookName], $handler);
                }
            } else {
                throw new TaskBalancerException("Don't support hooks `$hookName`.");
            }
        } elseif (is_array($hookName)) {
            if (is_bool($handler) && $handler) {
                $this->handlers = [];
            }
            foreach ($hookName as $k => $v) {
                $this->hook($k, $v, false);
            }
        }
    }
1080444
def subset_hook_caller(self, name, remove_plugins):
        
        orig = getattr(self.hook, name)
        plugins_to_remove = [plug for plug in remove_plugins if hasattr(plug, name)]
        if plugins_to_remove:
            hc = _HookCaller(
                orig.name, orig._hookexec, orig.spec.namespace, orig.spec.opts
            )
            for hookimpl in orig.get_hookimpls():
                plugin = hookimpl.plugin
                if plugin not in plugins_to_remove:
                    hc._add_hookimpl(hookimpl)
                    # we also keep track of this hook caller so it
                    # gets properly removed on plugin unregistration
                    self._plugin2hookcallers.setdefault(plugin, []).append(hc)
            return hc
        return orig
60449
public function hook($event, callable $callback, $priority = 10)
    {
        $this->app->hook($event, $callback, $priority);
    }
713244
def hook_point(self, hook_name):
        
        self.my_daemon.hook_point(hook_name=hook_name, handle=self)
711576
public static function register($name, $callback) {
		$name = static::slug($name);
		if( empty(static::$hooks[$name]) ) {
			throw new \Exception('No hook with this name');
		}
		return static::$hooks[$name]->registerHook($callback);
	}
902725
public function hook($name, $callable, $priority = 10, $override = false)
    {
        if ($override) {
            $this->clearHooks($name);
        }

        return parent::hook($name, $callable, $priority);
    }
761298
def pre_run_hook(self, func, prefix=None):
        
        cf = self.capture(func, prefix=prefix)
        self.pre_run_hooks.append(cf)
        return cf