我曾经在 composer.json
文件中指定应用程序的版本,直到我在 Stack Overflow 上读到这是一种不好的做法。在 PHP Laravel 应用程序中指定应用程序版本的标准文件是什么?(例如:在 .NET 中,它是配置文件,在 iOS 中,它是 info.plist,在 Android 中,它是 Manifest 等等...)
config/app.php
绝对是这类信息的存放位置。
为什么?因为配置文件应该被纳入版本控制流程,并且它们(应该)包含有关应用程序的非敏感信息。这是一个简单版本指示器的完美位置。
在数组的name
索引下,您可以设置像这样的version
索引。
/*
|--------------------------------------------------------------------------
| Application Version
|--------------------------------------------------------------------------
|
| This value is the version of your application. This value is used when
| the framework needs to place the application's version in a notification
| or any other location as required by the application or its packages.
*/
'version' => '1.0.0',
php artisan config:clear
解决了问题。 - Brettins@delatbabel
这是一个版本的良好开端
config/app.php
'version' => env('APP_VERSION', '1.0.0'),
针对config/bugsnag:
'app_version' => env('APP_VERSION', '1.0.0'),
然后您可以简单地通过以下方式获取您的版本:
config('app.version')
现在在Docker中,您可以在构建时设置默认版本:
ENV APP_VERSION=1.0.0
ARG BUILD_NR
ENV APP_VERSION=1.0.$BUILD_NR
deliver-prod:
machine: true
steps:
- checkout
- docker build --build-arg BUILD_NR=$CIRCLE_BUILD_NUM .
我通常在 .env 文件中设置它,然后在配置文件中使用它。
例如,.env 文件内容如下:
APP_VERSION=2.1
config/app.php是这样写的:
'version' => env('APP_VERSION', '0.0.1-alpha'),
我的做法是:GitLab管道在每次成功构建后编写“version.php”文件。该文件的内容如下:
<?php const VERSION = '1.2.3';
require_once __DIR__ . '/../version.php';
...
'version' => VERSION,
...
Route::get('api/version', function () {
return ["version" => config('app.version')];
})
->name('version');
1.0.1
、1.2.0
、1.5.3-RC2
等。 - Christopher Francisco