在哪里指定 Laravel 应用程序的应用程序版本?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/32061775/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 12:12:46  来源:igfitidea点击:

Where to specify an app version on a Laravel app?

phplaravellaravel-5

提问by Christopher Francisco

I used to specify the app version inside composer.jsonuntil I read somewhere here in Stack Overflow that it was a bad practice. What is the standard file to specifying the app version on a PHP Laravel application? (i.e: in .NETthat'd be the config file, on iOSit'd be the info.plist, on Androidit'd be the Manifest, etc...)

我曾经在里面指定应用程序版本,composer.json直到我在 Stack Overflow 的某处读到这是一种不好的做法。在 PHP Laravel 应用程序上指定应用程序版本的标准文件是什么?(即:在.NET 中,它是配置文件,在iOS 上它是info.plist,在Android 上它是Manifest等......)

回答by George Dimitriadis

config/app.phpis definitely the place for such information.

config/app.php绝对是此类信息的地方。

Why ? Because the configuration files are (or should be) included in your versioning flow and they (should) contain non-sensitive information about your application. The perfect place for a simple version indicator.

为什么 ?因为配置文件(或应该)包含在您的版本控制流程中,并且它们(应该)包含有关您的应用程序的非敏感信息。简单版本指示器的理想场所。

under the nameindex of the array, you could set a versionindex like this

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',

回答by Joel Harkes

@delatbabel

@delatbabel

has a great start for version

版本有一个很好的开始

config/app.php

配置/app.php

'version' => env('APP_VERSION', '1.0.0'),

for config/bugsnag:

对于配置/bugsnag:

'app_version' => env('APP_VERSION', '1.0.0'),

than you can simply get your version with:

比您可以简单地获得您的版本:

config('app.version')

Docker

码头工人

now in docker you could set a default version on build:

现在在 docker 中,您可以在构建时设置默认版本:

ENV APP_VERSION=1.0.0

for example with circle CI you can add your build number:

例如,使用 circle CI,您可以添加内部版本号:

ARG BUILD_NR
ENV APP_VERSION=1.0.$BUILD_NR

Now in your config.yml, you can add following job commando:

现在在您的 config.yml 中,您可以添加以下作业突击队:

 deliver-prod:
    machine: true
    steps:
      - checkout
      - docker build --build-arg BUILD_NR=$CIRCLE_BUILD_NUM .

回答by delatbabel

I normally set it in my .env file and then pick that up in a config.

我通常在我的 .env 文件中设置它,然后在配置中选择它。

e.g. .env says:

例如 .env 说:

APP_VERSION=2.1

config/app.php says:

config/app.php 说:

'version' => env('APP_VERSION', '0.0.1-alpha'),

回答by John

Good answers so far but whenever you run "composer update", your version may change requiring you to update your .env or config.app file (or wherever you specified the version) each time to maintain correct versioning.

到目前为止很好的答案,但是每当您运行“composer update”时,您的版本可能会发生变化,需要您每次更新 .env 或 config.app 文件(或您指定版本的任何地方)以保持正确的版本控制。

There is another alternative using blade (if you use blade). Add the following example code anywhere you want (in a .php file), and the version will automatically be updated whenever composer updates the version:

还有另一种使用刀片的替代方法(如果您使用刀片)。将以下示例代码添加到您想要的任何位置(在 .php 文件中),每当 composer 更新版本时,版本将自动更新:

<p>My current Laravel version is:&nbsp;&nbsp;&nbsp;{{ app()::VERSION }}</p>