From 997c5a0a135b1f0d7bbc08d32c76933789841bdc Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Thu, 12 Nov 2015 19:52:20 +0100 Subject: [PATCH] Hook: normalize names --- library/Icinga/Application/Hook.php | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/library/Icinga/Application/Hook.php b/library/Icinga/Application/Hook.php index ed38a7fe8..3c3cb0cc8 100644 --- a/library/Icinga/Application/Hook.php +++ b/library/Icinga/Application/Hook.php @@ -68,9 +68,24 @@ class Hook */ public static function has($name) { + $name = self::normalizeHookName($name); return array_key_exists($name, self::$hooks); } + protected static function normalizeHookName($name) + { + if (strpos($name, '\\') === false) { + $parts = explode('/', $name); + foreach ($parts as & $part) { + $part = ucfirst($part); + } + + return implode('\\', $parts); + } + + return $name; + } + /** * Create or return an instance of a given hook * @@ -83,6 +98,8 @@ class Hook */ public static function createInstance($name, $key) { + $name = self::normalizeHookName($name); + if (!self::has($name, $key)) { return null; } @@ -134,6 +151,8 @@ class Hook */ private static function assertValidHook($instance, $name) { + $name = self::normalizeHookName($name); + $suffix = self::$classSuffix; // 'Hook' $base = self::$BASE_NS; // 'Icinga\\Web\\Hook\\' @@ -208,6 +227,8 @@ class Hook */ public static function first($name) { + $name = self::normalizeHookName($name); + if (self::has($name)) { return self::createInstance($name, key(self::$hooks[$name])); } @@ -223,6 +244,8 @@ class Hook */ public static function register($name, $key, $class) { + $name = self::normalizeHookName($name); + if (!isset(self::$hooks[$name])) { self::$hooks[$name] = array(); }