Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Steur <thomas.steur@googlemail.com>2014-07-02 06:23:42 +0400
committerThomas Steur <thomas.steur@googlemail.com>2014-07-02 06:23:42 +0400
commit5ce45d1a948bd965f63c333d8f2ed0f76f74cc92 (patch)
tree79d9d6d1f9e3dd2675c69442b0cff9ed8d5321e5 /core/Development.php
parent3a8aa4a5198b4f0b917ff72fbd32d14896c8fd67 (diff)
added development flag which allows us to not cache static cache and to make some more checks when developers develop plugins
Diffstat (limited to 'core/Development.php')
-rw-r--r--core/Development.php85
1 files changed, 85 insertions, 0 deletions
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 @@
+<?php
+/**
+ * Piwik - free/libre analytics platform
+ *
+ * @link http://piwik.org
+ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
+ *
+ */
+
+namespace Piwik;
+
+use \Exception;
+
+/**
+ * Development related checks and tools
+ */
+class Development
+{
+ private static $isEnabled = null;
+
+ /**
+ * Returns `true` if segmentation is allowed for this user, `false` if otherwise.
+ *
+ * @return bool
+ * @api
+ */
+ public static function isEnabled()
+ {
+ if (is_null(self::$isEnabled)) {
+ self::$isEnabled = (bool) Config::getInstance()->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);
+ }
+}