From 022507a72c4135c794fe5263e625be79eae51fbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Munsch?= Date: Wed, 4 Aug 2021 13:13:51 +0200 Subject: [PATCH] api config get composer.json version number --- app/Lib/Helper.php | 21 +++++++++++++++++++++ config/api.php | 4 +++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/app/Lib/Helper.php b/app/Lib/Helper.php index 327f9f4..889a26e 100644 --- a/app/Lib/Helper.php +++ b/app/Lib/Helper.php @@ -10,6 +10,14 @@ use Illuminate\Support\Facades\Route; */ class Helper { + + /** + * Package infos + * + * @var array + */ + private static $packageInfos; + /** * Tells if the request is within apiV2 routes * @@ -71,4 +79,17 @@ class Helper { return Route::getRoutes()->getByName(static::getRouteName($request)); } + + /** + * Get composer.json infos + * + * @return array + */ + public static function getPackageInfo(): array + { + if (!static::$packageInfos) { + static::$packageInfos = \json_decode(\file_get_contents(__DIR__ . '/../../composer.json'), true); + } + return static::$packageInfos; + } } diff --git a/config/api.php b/config/api.php index c0641e1..1f6a224 100644 --- a/config/api.php +++ b/config/api.php @@ -1,11 +1,13 @@ '2.0.0', + 'version' => Helper::getPackageInfo()['version'], /** * Api Token timeout in minutes