Run Hook

Runs a particular hook

@param array The hook details

@return bool
355850
public function _run_hook($aData)
    {
        if (!is_array($aData)) {
            return false;
        }

        /** -----------------------------------
         * Safety - Prevents run-away loops
         * ------------------------------------
         * If the script being called happens to have the same
         * hook call within it a loop can happen
         */
        if ($this->bCustomHooksInProgress == true) {
            return;
        }

        // Set file path
        if (!isset($aData['filepath']) || !isset($aData['filename'])) {
            return false;
        }

        //  Using absolute filepath?
        if (substr($aData['filepath'], 0, 1) == '/') {

            $sFilePath = rtrim($aData['filepath'], '/') . '/';
            $sFilePath .= $aData['filename'];

        } else {

            $sFilePath = APPPATH;
            $sFilePath .= rtrim($aData['filepath'], '/') . '/';
            $sFilePath .= $aData['filename'];
        }

        if (!file_exists($sFilePath)) {
            return false;
        }

        // Set class/function name
        $sClass    = false;
        $sFunction = false;
        $sParams   = '';

        if (isset($aData['class']) && $aData['class'] != '') {
            $sClass = $aData['class'];
        }

        if (isset($aData['function'])) {
            $sFunction = $aData['function'];
        }

        if (isset($aData['params'])) {
            $sParams = $aData['params'];
        }

        if ($sClass === false && $sFunction === false) {
            return false;
        }

        // Set the in_progress flag
        $this->in_progress = true;

        // Call the requested class and/or function
        if ($sClass !== false) {

            if (!class_exists($sClass)) {
                require($sFilePath);
            }

            $HOOK = new $sClass();
            $HOOK->$sFunction($sParams);

        } else {

            if (!function_exists($sFunction)) {
                require($sFilePath);
            }

            $sFunction($sParams);
        }

        $this->in_progress = false;
        return true;
    }
861338
public function runHook($name, $vendor, array $assets = [])
    {
        if (!isset($this->hooks[$name]) || !is_callable($this->hooks[$name])) {
            return null;
        }

        return call_user_func($this->hooks[$name], $this, $vendor, $assets);
    }
759813
protected function runCustomHook($aData)
    {
        if (!is_array($aData)) {
            return false;
        }

        /** -----------------------------------
         * Safety - Prevents run-away loops
         * ------------------------------------
         * If the script being called happens to have the same
         * hook call within it a loop can happen
         */
        if ($this->bCustomHooksInProgress == true) {
            return;
        }

        // Set class/method name
        $oClass  = null;
        $sMethod = null;
        $aParams = [];

        if (isset($aData['classref'])) {
            $oClass =& $aData['classref'];
        }

        if (isset($aData['method'])) {
            $sMethod = $aData['method'];
        }
        if (isset($aData['params'])) {
            $aParams = $aData['params'];
        }

        if (!is_object($oClass) || !method_exists($oClass, $sMethod)) {
            return false;
        }

        // Set the in_progress flag
        $this->bCustomHooksInProgress = true;

        // Call the requested class and/or function
        $oClass->$sMethod($aParams);
        $this->bCustomHooksInProgress = false;
        return true;
    }
990741
def run_hooks(hooks, halt_on_abort: true)
      hooks.each do |hook|
        run_hook(hook)
        break if aborted? && halt_on_abort
      end
    end
624969
public function applyHook($name, $hookArg = null)
    {
        if (!isset($this->hooks[$name])) {
            $this->hooks[$name] = array(array());
        }
        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]);
            }
            foreach ($this->hooks[$name] as $priority) {
                if (!empty($priority)) {
                    foreach ($priority as $callable) {
                        call_user_func($callable, $hookArg);
                    }
                }
            }
        }
    }
677193
public function call($hookName, $arg = '') : bool
    {
        $hookName = $this->sanitizeKeyName($hookName);
        if (! $hookName) {
            return false;
        }

        if (! isset($this->actions[$hookName])) {
            $this->actions[$hookName] = 1;
        } else {
            $this->actions[$hookName]++;
        }

        if (! isset($this->filters[$hookName])) {
            return false;
        }

        $this->current[] = $hookName;

        $args = [];
        if (is_array($arg) && 1 == count($arg) && isset($arg[0]) && is_object($arg[0])) {
            $args[] =& $arg[0];
        } else {
            $args[] = $arg;
        }

        for ($a = 2, $num = func_num_args(); $a < $num; $a++) {
            $args[] = func_get_arg($a);
        }

        // Sort
        if (! isset($this->merged[$hookName])) {
            ksort($this->filters[$hookName]);
            $this->merged[$hookName] = true;
        }
        reset($this->filters[$hookName]);
        do {
            foreach (current($this->filters[$hookName]) as $collection) {
                if (!is_null($collection[self::KEY_FUNCTION])) {
                    call_user_func_array(
                        $collection[self::KEY_FUNCTION],
                        array_slice(
                            $args,
                            0,
                            (int) $collection[self::KEY_ACCEPTED_ARGS]
                        )
                    );
                }
            }
        } while (next($this->filters[$hookName]) !== false);

        array_pop($this->current);
        return true;
    }
163212
public function run() : void
    {
        $hooks = $this->getHooksToInstall();

        foreach ($hooks as $hook => $ask) {
            $this->installHook($hook, ($ask && !$this->force));
        }
    }
1195125
protected function seedHook(Hook $hook)
    {
        $folders = (array) $hook->getComposerHookKey('seeders', []);
        $basePath = $hook->getPath().'/';

        $this->runSeeders($folders, $basePath);
    }
81836
def run_hook(hook_name, *args, &block)
      hooks.find {|hook| hook.name == hook_name }.run(self, *args, &block)
    end
944682
public function run() {
        $results = [
            $this->doDelete(),
            $this->doUpdate(),
            $this->doCreate()
        ];
        return array_search(false, $results, true) === false;
    }
435050
public static function runHook( $hook_name, $args = array() ) {
		global $pgHooks;

		if( !isset( $pgHooks[$hook_name] ) ) return null;

		if( !is_array( $pgHooks[$hook_name] ) ) {
			throw new HookError( "Hook assignment for event `$hook_name` is not an array. Syntax is " . '$pgHooks[\'hookname\'][] = "hook_function";' );
		}

		$method = null;
		foreach( $pgHooks[$hook_name] as $function ){
			if( is_array( $function ) ) {
				if( count( $function ) < 2 ) {
					throw new HookError( "Not enough parameters in array specified for `$hook_name` hook" );
				} elseif( is_object( $function[0] ) ) {
					$object = $function[0];
					$method = $function[1];
					if( count( $function ) > 2 ) {
						$data = $function[2];
					}
				} elseif( is_string( $function[0] ) ) {
					$method = $function[0];
					if( count( $function ) > 1 ) {
						$data = $function[1];
					}
				}

			} elseif( is_string( $function ) ) {
				$method = $function;
			}

			if( isset( $data ) ) {
				$args = array_merge( array( $data ), $args );
			}

			if( isset( $object ) ) {
				$fncarr = array( $object, $method );
			} elseif( is_string( $method ) && in_string( "::", $method ) ) {
				$fncarr = explode( "::", $method );
			} else {
				$fncarr = $method;
			}

			//is_callable( $fncarr ); //Apparently this is a bug. Thanks, MW!

			if( !is_callable( $fncarr ) ) {
				throw new BadEntryError( "MissingFunction", "Hook function $fncarr was not defined" );
			}

			$hookRet = call_user_func_array( $fncarr, $args );

			if( !is_null( $hookRet ) ) return $hookRet;

		}

	}
862373
function runHook (instance, type) {
  var hook = type ? 'response' : 'request'
  hook += 'Hook'
  if (instance[hook] && isFunction(instance[hook])) {
    instance[hook]()
  }
}
186155
public function runThreads(array $threads): bool
    {
        if (!$this->disabled) {
            foreach ($threads as $thread) {
                $this->runThreadPool->add($thread);
                try {
                    $this->commander->runAsync(new ThreadRun(
                        $this->client,
                        $thread->getId(),
                        $thread->getApplicationId(),
                        $thread->getUniqueId(),
                        $thread->getArguments()
                    ));
                } catch (\Throwable $e) {
                    $thread->run();
                    Log::log($e->getMessage());
                }
            }
        } else {
            $this->enable();
        }

        return true;
    }
1309854
public function exec_hook($hook, $args = array())
    {
        if (!is_array($args)) {
            $args = array('arg' => $args);
        }

        // TODO: avoid recursion by checking in_array($hook, $this->exec_stack) ?

        $args += array('abort' => false);
        array_push($this->exec_stack, $hook);

        // Use for loop here, so handlers added in the hook will be executed too
        if (!empty($this->handlers[$hook])) {
            for ($i = 0; $i < count($this->handlers[$hook]); $i++) {
                $ret = call_user_func($this->handlers[$hook][$i], $args);
                if ($ret && is_array($ret)) {
                    $args = $ret + $args;
                }

                if ($args['break']) {
                    break;
                }
            }
        }

        array_pop($this->exec_stack);
        return $args;
    }
582773
public function run(array $data) {
        $this->getLogger()->info('Executing on data ' . md5(print_r($data, true)));

        $this->setData($data);

        $path = array();
        $this->runFilters($data, $path);

        return true;
    }
644930
function runHooks(request, response, hooks) {
    var promise = Promise.resolve();
    for (var i = 0; i < hooks.length; i++) {
      promise = promise.then(hooks[i].bind(this, request, response));
    }
    return promise;
  }
655293
function executeHooks(data, allHooks, checkHooks, creationMode) {
    var hooksToCall = creationMode ? allHooks : checkHooks;
    if (hooksToCall) {
        callHooks(data, hooksToCall);
    }
}