getMessage() ); unset(self::$hooks[$name][$key]); return null; } self::assertValidHook($instance,$name); self::$instances[$name][$key] = $instance; return $instance; } private static function assertValidHook(&$instance, $name) { $base_class = self::$BASE_NS.ucfirst($name); if (! $instance instanceof $base_class) { throw new ProgrammingError(sprintf( '%s is not an instance of %s', get_class($instance), $base_class )); } } public static function all($name) { if (!self::has($name)) { return array(); } foreach (self::$hooks[$name] as $key=>$hook) { if(self::createInstance($name,$key) === null) return array(); } return self::$instances[$name]; } public static function first($name) { return self::createInstance($name,key(self::$hooks[$name])); } public static function register($name, $key, $class) { self::$hooks[$name][$key] = $class; } }