本文整理汇总了PHP中Hook::hook_files方法的典型用法代码示例。如果您正苦于以下问题:PHP Hook::hook_files方法的具体用法?PHP Hook::hook_files怎么用?PHP Hook::hook_files使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Hook
的用法示例。
在下文中一共展示了Hook::hook_files方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: run
/**
* Run the instance of a given hook
*
* @param string $namespace The namespace (addon/aspect) calling the hook
* @param string $hook Name of hook
* @param string $type Cumulative/replace/call
* @param mixed $return Pass-through values
* @param mixed $data Data to pass to hooked method
* @return mixed
*/
public static function run($namespace, $hook, $type = NULL, $return = NULL, $data = NULL)
{
$mark_as_init = !self::$hooks_found;
if (!self::$hooks_found) {
$hash = Debug::markStart('hooks', 'finding');
// we went finding
self::$hooks_found = true;
// set paths
$addons_path = BASE_PATH . Config::getAddOnsPath();
$bundles_path = APP_PATH . '/core/bundles';
$pattern = '/*/hooks.*.php';
// globbing with a brace doesn't seem to work on some system,
// it's not just Windows-based servers, seems to affect some
// linux-based ones too
$bundles = glob($bundles_path . $pattern);
$addons = glob($addons_path . $pattern);
$bundles = empty($bundles) ? array() : $bundles;
$addons = empty($addons) ? array() : $addons;
self::$hook_files = array_merge($bundles, $addons);
Debug::markEnd($hash);
}
$hash = Debug::markStart('hooks', 'running');
if (self::$hook_files) {
foreach (self::$hook_files as $file) {
$name = substr($file, strrpos($file, '/') + 7);
$name = substr($name, 0, strlen($name) - 4);
$class_name = 'Hooks_' . $name;
if (!is_callable(array($class_name, $namespace . '__' . $hook), false)) {
continue;
}
try {
$hook_class = Resource::loadHooks($name);
$method = $namespace . '__' . $hook;
if ($type == 'cumulative') {
$response = $hook_class->{$method}($data);
if (is_array($response)) {
$return = is_array($return) ? $return + $response : $response;
} else {
$return .= $response;
}
} elseif ($type == 'replace') {
$return = $hook_class->{$method}($data);
} else {
$hook_class->{$method}($data);
}
} catch (Exception $e) {
continue;
}
}
}
if ($mark_as_init) {
Debug::markMilestone('hooks initialized');
}
Debug::markEnd($hash);
return $return;
}
示例2: run
/**
* Run the instance of a given hook
*
* @param string $namespace The namespace (addon/aspect) calling the hook
* @param string $hook Name of hook
* @param string $type Cumulative/replace/call
* @param mixed $return Pass-through values
* @param mixed $data Data to pass to hooked method
* @return mixed
*/
public static function run($namespace, $hook, $type = NULL, $return = NULL, $data = NULL)
{
$mark_as_init = !self::$hooks_found;
if (!self::$hooks_found) {
$hash = Debug::markStart('hooks', 'finding');
// we went finding
self::$hooks_found = true;
// set paths
$addons_path = BASE_PATH . Config::getAddOnsPath();
$bundles_path = APP_PATH . '/core/bundles';
$pattern = '/*/hooks.*.php';
// muuulllllti-gloooobbb
self::$hook_files = glob('{' . $bundles_path . $pattern . ',' . $addons_path . $pattern . '}', GLOB_BRACE);
Debug::markEnd($hash);
}
$hash = Debug::markStart('hooks', 'running');
if (self::$hook_files) {
foreach (self::$hook_files as $file) {
$name = substr($file, strrpos($file, '/') + 7);
$name = substr($name, 0, strlen($name) - 4);
$class_name = 'Hooks_' . $name;
if (!is_callable(array($class_name, $namespace . '__' . $hook), false)) {
continue;
}
try {
$hook_class = Resource::loadHooks($name);
$method = $namespace . '__' . $hook;
if ($type == 'cumulative') {
$response = $hook_class->{$method}($data);
if (is_array($response)) {
$return = is_array($return) ? $return + $response : $response;
} else {
$return .= $response;
}
} elseif ($type == 'replace') {
$return = $hook_class->{$method}($data);
} else {
$hook_class->{$method}($data);
}
} catch (Exception $e) {
continue;
}
}
}
if ($mark_as_init) {
Debug::markMilestone('hooks initialized');
}
Debug::markEnd($hash);
return $return;
}