From 0dfd8041cfa9ab008fc660965eced85947158d7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Hr=C3=A1=C5=A1ek?= Date: Fri, 5 Apr 2019 09:28:30 +0200 Subject: [PATCH] Add MinAppVersion behavior --- src/behaviors/MinAppVersion.php | 60 +++++++++++++++++++ src/exceptions/MinAppVersionHttpException.php | 20 +++++++ 2 files changed, 80 insertions(+) create mode 100644 src/behaviors/MinAppVersion.php create mode 100644 src/exceptions/MinAppVersionHttpException.php diff --git a/src/behaviors/MinAppVersion.php b/src/behaviors/MinAppVersion.php new file mode 100644 index 0000000..25096db --- /dev/null +++ b/src/behaviors/MinAppVersion.php @@ -0,0 +1,60 @@ +device = Yii::$app->get('device', false); + } + + /** + * @inheritdoc + */ + public function beforeAction() + { + if (!$this->device) { + return true; + } + + $appVersion = explode('.', $this->appVersion); + $deviceVersion = explode('.', $this->device->appVersion); + + foreach ($deviceVersion as $index => $value) { + $minVersion = $appVersion[$index] ?? 0; + + if ($index === count($deviceVersion) - 1 && $minVersion > $value) { + return false; + } + elseif ($minVersion >= $value) { + return false; + } + } + + return true; + } + + protected function handleError() + { + // + } +} diff --git a/src/exceptions/MinAppVersionHttpException.php b/src/exceptions/MinAppVersionHttpException.php new file mode 100644 index 0000000..676397b --- /dev/null +++ b/src/exceptions/MinAppVersionHttpException.php @@ -0,0 +1,20 @@ +