diff options
author | Frederic Guillot <fred@kanboard.net> | 2017-01-08 17:02:31 -0500 |
---|---|---|
committer | Frederic Guillot <fred@kanboard.net> | 2017-01-08 17:02:31 -0500 |
commit | 07f9700179da74b056485375652c3b26d6fbce0d (patch) | |
tree | 027408d8895514daa33297d1fbfdda7f26f3dc1c /app/Core/Plugin/Version.php | |
parent | 17ac414d744155d77c729f150115e8fd9e18f285 (diff) |
Offer the possibility to define version compatibility from plugins
Diffstat (limited to 'app/Core/Plugin/Version.php')
-rw-r--r-- | app/Core/Plugin/Version.php | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/app/Core/Plugin/Version.php b/app/Core/Plugin/Version.php new file mode 100644 index 00000000..ba5e0443 --- /dev/null +++ b/app/Core/Plugin/Version.php @@ -0,0 +1,38 @@ +<?php + +namespace Kanboard\Core\Plugin; + +/** + * Class Version + * + * @package Kanboard\Core\Plugin + * @author Frederic Guillot + */ +class Version +{ + /** + * Check plugin version compatibility with application version + * + * @param string $pluginCompatibleVersion + * @param string $appVersion + * @return bool + */ + public static function isCompatible($pluginCompatibleVersion, $appVersion = APP_VERSION) + { + if (strpos($appVersion, 'master') !== false) { + return true; + } + + $appVersion = str_replace('v', '', $appVersion); + $pluginCompatibleVersion = str_replace('v', '', $pluginCompatibleVersion); + + foreach (array('>=', '>', '<=', '<') as $operator) { + if (strpos($pluginCompatibleVersion, $operator) === 0) { + $pluginVersion = substr($pluginCompatibleVersion, strlen($operator)); + return version_compare($appVersion, $pluginVersion, $operator); + } + } + + return $pluginCompatibleVersion === $appVersion; + } +} |