Runs any callables attached to an action.

@since 150321 Adding hook API for plugins.

@param string $hook The name of an action hook.
770136
public function doAction($hook)
    {
        $hook = (string) $hook;
        if (empty($this->hooks[$hook])) {
            return; // No hooks.
        }
        $hook_actions = $this->hooks[$hook];
        $args         = func_get_args();
        ksort($hook_actions);

        foreach ($hook_actions as $_hook_action) {
            foreach ($_hook_action as $_action) {
                if (!isset($_action['function'], $_action['accepted_args'])) {
                    continue; // Not a valid filter in this case.
                }
                call_user_func_array($_action['function'], array_slice($args, 1, $_action['accepted_args']));
            }
        }
        unset($_hook_action, $_action); // Housekeeping.
    }
1316226
def _run_hooks(self):
        """"""
        for hook in self.hooks:
            getattr(self, hook)(self._state)
655293
function executeHooks(data, allHooks, checkHooks, creationMode) {
    var hooksToCall = creationMode ? allHooks : checkHooks;
    if (hooksToCall) {
        callHooks(data, hooksToCall);
    }
}
389403
def add_hook(self, hook):
        
        h = hook.hash
        self.hooks[h] = hook
493338
private function runHooks()
    {
        if (class_exists($Hook = 'Josantonius\Hook\Hook')) {
            $Hook::getInstance(self::$id);
            if (isset($this->settings['hooks'])) {
                $Hook::addActions($this->settings['hooks']);
                unset($this->settings['hooks']);
            }
            $Hook::doAction('after-load-hooks');
        }
    }
512472
def add_hook(self, name, function):
        
        if not callable(function):
            return ValueError('Hook function should be callable')
        if name not in self.hooks:
            self.hooks[name] = []
        self.hooks[name].append(function)
        return self
1076803
public function with($hook)
    {
        if (!in_array($hook, PluginInterface::VALID_HOOKS)) {
            throw new InvalidArgumentException("The `{$hook}` hook is not a known plugin hook.");
        }
        foreach ($this as $plugin) {
            if ($plugin->isEnabled($hook)) {
                yield $plugin;
            }
        }
    }
136932
protected function handleHookFailure(Hook $hook)
    {
        $this->lineLength += 1;
        $this->failures[] = $hook;
        $failure = $this->formatter->red('F');
        $this->console->write($failure);
    }
743451
public function apply(callable $action)
    {
        foreach ($this->each() as $k => $v) {
            call_user_func($action, $v, $k);
        }
    }
190317
def run_hook(self, hook, *args, **kwargs):
        
        for plugin in self.raw_plugins:
            if hasattr(plugin, hook):
                self.logger.debug('Calling hook {0} in plugin {1}'.format(hook, plugin.__name__))
                getattr(plugin, hook)(*args, **kwargs)
1086367
public function hooks()
    {
        $this->hook->action(
            $this->isAllowedArea($this->getArea()),
            [$this, 'handleAction']
        )->dispatch();

        if (! empty($this->getArgument('execution'))) {
            $this->hook->filter(
                'script_loader_tag',
                [$this, 'addExecutionTypes']
            )->dispatch();
        }
    }
342787
def run_hooks_for(event,*args)
      results = global_hooks_for(event).map { |prc| prc.call(*args) } || [true]
      results << hooks_for(event).map { |method| send(method,*args) }
      results = false if results.any? {|r| false == r }
      results
    end
696379
public function run() : void
    {
        /** @var \CaptainHook\App\Config\Hook $hookConfig */
        $hookConfig = $this->config->getHookConfig($this->hook);
        $actions    = $hookConfig->getActions();

        // if hook is not enabled in captainhook configuration skip the execution
        if (!$hookConfig->isEnabled()) {
            $this->io->write($this->formatHookHeadline('Skip'));
            return;
        }
        // if no actions are configured do nothing
        if (count($actions) === 0) {
            $this->io->write(['', '<info>No actions to execute</info>']);
            return;
        }

        $this->io->write($this->formatHookHeadline('Execute'));
        $this->beforeHook();
        foreach ($actions as $action) {
            $this->handleAction($action);
        }
        $this->afterHook();
    }
790896
def run_hooks(self, name, event=None, context=None):
        
        hooks = {
            "pre:setup": lambda p: p.pre_setup(self),
            "post:setup": lambda p: p.post_setup(self),
            "pre:invoke": lambda p: p.pre_invoke(event, context),
            "post:invoke": lambda p: p.post_invoke(event, context),
            "pre:report": lambda p: p.pre_report(self.report),
            "post:report": lambda p: p.post_report(self.report),
        }

        if name in hooks:
            for p in self.plugins:
                if p.enabled:
                    try:
                        hooks[name](p)
                    except Exception as e:
                        logger.error(
                            "IOpipe plugin %s hook raised error" % (name, str(e))
                        )
                        logger.exception(e)
473759
public function writeHookFile(string $hook) : void
    {
        $hooksDir = $this->repository->getHooksDir();
        $hookFile = $hooksDir . DIRECTORY_SEPARATOR . $hook;
        $doIt     = true;

        // if hook is configured and no force option is set
        // ask the user if overwriting the hook is ok
        if ($this->needInstallConfirmation($hook)) {
            $ans  = $this->io->ask('  <comment>The \'' . $hook . '\' hook exists! Overwrite? [y,n]</comment> ', 'n');
            $doIt = IOUtil::answerToBool($ans);
        }

        if ($doIt) {
            $code = $this->getHookSourceCode($hook);
            $file = new File($hookFile);
            $file->write($code);
            chmod($hookFile, 0755);
            $this->io->write('  <info>\'' . $hook . '\' hook installed successfully</info>');
        }
    }
249654
public function invokePluginsHook($hook, $args)
    {
        foreach ($this->getPlugins() as $plugin) {
            if (method_exists($plugin, $hook)) {
                call_user_func_array(array($plugin, $hook), $args);
            }
        }
    }
1127614
protected function triggerHook($hook, $image)
    {
        if (is_callable($hook)) {
            $hook($image);
        }

        // We assume that the user is passing the hook class name
        if (is_string($hook)) {
            $instance = app($hook);
            $instance->handle($image);
        }
    }