zenstruck / version-bundle
此包已被废弃,不再维护。未建议替代包。
跟踪您的Symfony2应用版本
v1.0.0
2012-06-29 16:08 UTC
Requires
- php: >=5.3.0
- symfony/symfony: 2.*
This package is not auto-updated.
Last update: 2022-02-01 12:20:55 UTC
README
跟踪您的Symfony2应用版本。了解应用在预发布/生产环境中的构建/版本号非常重要。
许多项目都有由开发者或CI服务器创建的VERSION或BUILD文件。此包提供了一个块、twig函数和Web调试工具栏面板,用于输出应用和Symfony的版本。版本在整个项目中作为服务可用。您可以将当前版本注入到生产环境的meta
标签中。
安装
- 通过composer安装此包
{ "require": { // ... "zenstruck/version-bundle": "dev-master" } }
-
在项目的根目录下创建一个
VERSION
文件 -
配置此包
# Example # app/config_dev.yml zenstruck_version: enabled: true toolbar: true #app/config_staging.yml zenstruck_version: enabled: true toolbar: false block: enabled: true
使用方法
当启用时,此插件定义了两个twig函数
version()
: 输出当前应用版本(定义在您的VERSION
文件中)symfony()
: 输出当前Symfony版本(定义在Symfony\Component\HttpKernel\Kernel::VERSION
中)
并向Symfony的服务容器添加一个服务
zenstruck.version.data_collector
示例
在控制器中访问服务
...
public function indexAction()
{
$versionDC = $this->get('zenstruck.version.data_collector');
$appVersion = $versionDC->getVersion();
$symfonyVersion = $versionDC->getSymfony();
...
}
...
在模板中渲染
{# twig template #}
{{ version() }}
{{ symfony() }}
渲染包含应用版本和Symfony版本的meta
标签
...
<meta name="version" content="{{ version() }}" />
<meta name="symfony" content="{{ symfony() }}" />
...
扩展
使用您自己的版本数据收集器
-
覆盖默认的
VersionDataCollector
类// MyVersion.php use Zenstruck\Bundle\VersionBundle\DataCollector\VersionDataCollector; class MyVersion extends VersionDataCollector { public function getVersion() { return $myversion; } }
-
在
app/config.yml
中设置您的VersionDataCollector
类// app/config.yml parameters: zenstruck.version.data_collector.class: \MyVersion
完整的默认配置
# config.yml
zenstruck_version:
enabled: false # enable/disable service
toolbar: false # show in web debug toolbar
file: %kernel.root_dir%/../VERSION # the file containing version info
suffix: ~ # suffix text (ie "-dev")
version: ~ # overrides file/text with custom version
block:
enabled: false # enable/disable block
position: vb-bottom-right # other values: vb-bottom-left, vb-top-right, vb-top-left
prefix: "Version: " # text added to beginning of block