From 5ce45d1a948bd965f63c333d8f2ed0f76f74cc92 Mon Sep 17 00:00:00 2001 From: Thomas Steur Date: Wed, 2 Jul 2014 04:23:42 +0200 Subject: added development flag which allows us to not cache static cache and to make some more checks when developers develop plugins --- core/Development.php | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 core/Development.php (limited to 'core/Development.php') diff --git a/core/Development.php b/core/Development.php new file mode 100644 index 0000000000..880b55ea83 --- /dev/null +++ b/core/Development.php @@ -0,0 +1,85 @@ +General['development_mode']; + } + + return self::$isEnabled; + } + + public static function methodExists($classOrInstance, $method) + { + if (is_string($classOrInstance)) { + return class_exists($classOrInstance) && method_exists($classOrInstance, $method); + } + + return method_exists($classOrInstance, $method); + } + + public static function formatMethodCall($classOrInstance, $method) + { + if (is_object($classOrInstance)) { + $classOrInstance = get_class($classOrInstance); + } + + return $classOrInstance . '::' . $method . '()'; + } + + public static function checkMethodIsCallable($classOrInstance, $method, $prefixMessageIfError) + { + if (!self::isEnabled()) { + return; + } + + if (!self::methodExists($classOrInstance, $method)) { + self::error($prefixMessageIfError . ' "' . self::formatMethodCall($classOrInstance, $method) . '" does not exist. Please make sure to define such a method.'); + } + + if (!self::isCallableMethod($classOrInstance, $method)) { + self::error($prefixMessageIfError . ' "' . self::formatMethodCall($classOrInstance, $method) . '" is not callable. Please make sure to method is public'); + + } + } + + public static function isCallableMethod($classOrInstance, $method) + { + if (!self::methodExists($classOrInstance, $method)) { + return false; + } + + $reflection = new \ReflectionMethod($classOrInstance, $method); + return $reflection->isPublic(); + } + + public static function error($message) + { + $message .= ' (This error is only triggered in development mode. Your plugin still works when development mode is disabled but will lead in an error at some point. We highly recommend to fix this issue!)'; + throw new Exception($message); + } +} -- cgit v1.2.3