Invoke hook
@param  string $name The hook name
@param  mixed  ...   (Optional) Argument(s) for hooked functions, can specify multiple arguments
@return mixed
193613
public function fire($name)
    {
        $args = func_get_args();
        array_shift($args);

        if (!isset($this->hooks[$name])) {
            //$this->hooks[$name] = array(array());
            if (isset($args[0])) {
                return $args[0];
            } else {
                return;
            }
        }
        if (!empty($this->hooks[$name])) {
            // Sort by priority, low to high, if there's more than one priority
            if (count($this->hooks[$name]) > 1) {
                ksort($this->hooks[$name]);
            }

            $output = [];
            $count = 0;

            foreach ($this->hooks[$name] as $priority) {
                if (!empty($priority)) {
                    foreach ($priority as $callable) {
                        $output[] = call_user_func_array($callable, $args);
                        ++$count;
                    }
                }
            }

            // If we only have one hook binded or the argument is not an array,
            // let's return the first output
            if ($count == 1 || !is_array($args[0])) {
                return $output[0];
            } else {
                $data = [];
                // Move all the keys to the same level
                foreach ($output as $k => $vars) {
                    if ($k === 0) {
                        $data = $vars;
                        continue;
                    }
//                     проверить если в массиве есть callable
//                    $data = array_merge($data, $vars);
                    $data = $data + $vars;
                }
//                array_walk_recursive($output, function ($v, $k) use (&$data) {
//                    $data[] = $v;
//                });
                return $data;
                // Remove any duplicate key
//                return array_unique($data, SORT_REGULAR);
            }
        }
    }
898040
public function dispatch(string $name, $data = [])
    {
        if (!isset($this->events[$name])) {
            throw new \Exception("Event '$name' not found in ".__CLASS__.' in stack!');
        }

        foreach ($this->events[$name] as $callback) {
            switch ($callback) {
                case is_object($callback) && ($callback instanceof Closure):
                    return $callback($name, $data);
                    break;
                case string_has($callback, '@'):
                    return $this->callFunction($callback, $data);
                    break;
                case string_has($callback, '::'):
                    return $this->callUserFunctionEvent($callback);
                    break;
                case is_string($callback) && !string_has($callback, '@'):
                    call_user_func($callback, $data);
                    break;
            }
        }
    }
128195
protected function call_handler($name, array $params=array())
    {
        if ($this->handler === null) {
            return false;
        }

        if (!is_callable(array($this->handler, $name))) {
            Debug::Log(Debug::ERR, "call_handler function {$name} NOT CALLABLE");
            return false;
        }

        call_user_func_array(array($this->handler, $name), $params);
        return true;
    }
691477
protected function parseMiddleware($name)
    {
        list($name, $parameters) = array_pad(explode(':', $name, 2), 2, null);

        //
        $callable = isset($this->middleware[$name]) ? $this->middleware[$name] : $name;

        if (is_null($parameters)) {
            return $callable;
        }

        // When the callable is a string, we will add back the parameters before returning.
        else if (is_string($callable)) {
            return $callable .':' .$parameters;
        }

        // A callback with parameters; we should create a proper middleware closure for it.
        $parameters = explode(',', $parameters);

        return function ($passable, $stack) use ($callable, $parameters)
        {
            return call_user_func_array(
                $callable, array_merge(array($passable, $stack), $parameters)
            );
        };
    }
1112622
def hook(self, name):
        
        def wrapper(func):
            self.hooks.add(name, func)
            return func
        return wrapper
429222
function injectHook(options, name, hook) {
  const existing = options[name]
  options[name] = existing
    ? Array.isArray(existing) ? existing.concat(hook) : [existing, hook]
    : [hook]
}
1051852
protected function callHookHandler($hookName, $data = null)
    {
        if (array_key_exists($hookName, $this->handlers)) {
            $handlers = $this->handlers[$hookName] ?: [];
            $result = null;
            foreach ($handlers as $index => $handler) {
                $handlerArgs = $data === null ?
                               [$this, $index, &$handlers, $result] :
                               [$this, $data, $index, &$handlers, $result];
                $result = call_user_func_array($handler, $handlerArgs);
            }
            if ($result === null) {
                return true;
            }

            return $result;
        }

        return true;
    }
605011
private function parse_method_name( $name ){
		if ( preg_match( '|^(_?[^_]+_)(.*)$|', $name, $matches ) ) {
			$hook_type = trim( $matches[1], '_' ); //Methods prefixed with _ are always hooked
			$hook_name = $matches[2];

			if ( ! in_array( $hook_type , array( 'theme', 'action', 'filter', 'shortcode' ) ) ) {
				return false;
			}

			return compact( 'hook_type', 'hook_name' );
		}

		return false;
	}
1359840
public function hook($name, $callable, $priority = 10)
    {
        if (!isset($this->hooks[$name])) {
            $this->hooks[$name] = array(array());
        }
        if (is_callable($callable)) {
            $this->hooks[$name][(int) $priority][] = $callable;
        }
    }
545638
public function type($name)
    {
        $hook = $this->hooks()->where('name', $name)->first();

        if (!is_null($hook)) {
            return $hook->type;
        }
    }
157195
def invoke_hooks(hooks, name, *args, **kwargs):
    

    callbacks = hooks.get(name, [])

    for callback in callbacks:
        callback(*args, **kwargs)
1083135
public static function runHook($name, array $params = [ ])
    {
        static::ensureHookPoint($name);

        foreach (static::$hooks[ $name ] as $handler) {
            if ($handler instanceof \Closure) {

                call_user_func_array($handler, $params);
            } elseif (class_exists($handler)) {
                $instance = app()->make($handler);

                call_user_func_array([ $instance, 'handle' ], $params);
            }
        }
    }
1084066
public function make($name)
    {
        $studlyCase = studly_case($name);

        // Check if already exists
        if ($this->downloaded($name)) {
            throw new Exceptions\HookAlreadyExistsException("Hook [{$name}] already exists.");
        }

        event(new Events\MakingHook($name));

        // Ensure hooks folder exists
        if (!$this->filesystem->isDirectory(base_path('hooks'))) {
            $this->filesystem->makeDirectory(base_path('hooks'));
        }

        // Create folder for the new hook
        $this->filesystem->deleteDirectory(base_path("hooks/{$name}"));
        $this->filesystem->makeDirectory(base_path("hooks/{$name}"));

        // make stub files
        $this->makeStubFiles($name);

        event(new Events\MadeHook($name));
    }
1060727
public static function call_if_exists($name, $arguments = []) {
		if (self::exists($name)) {
			$application = Application::get();
			$classname = 'Hook_' . ucfirst($application->name);
			call_user_func_array([$classname, $name], $arguments);
		}
	}
953628
public function removeHook(string $name): bool
  {
    foreach ($this->hooks as $idx => $hook)
    {
      if (\strcasecmp($name,$hook->getName()==0)) {
        # Remove it
        unset( $this->hooks[$idx] );

        return true;
      }
    }

    return $this;
  }
839427
private function handleOptionName($name)
    {
        if (is_string($name)) {
            $name = explode('.', $name);
        }

        foreach ($this->optionNameHandlers as $handler) {
            $name = $handler($name);
        }

        return $name;
    }
282891
protected function handle($name, array $args = [])
    {
        if (isset($this->handlers[$name]) && is_callable($this->handlers[$name])) {
            array_unshift($args, $this);
            call_user_func_array($this->handlers[$name], $args);
        }
    }