zenstruck/version-bundle

此包已被废弃,不再维护。未建议替代包。

跟踪您的Symfony2应用版本

资助包维护!
kbond

安装次数: 7,504

依赖者: 0

建议者: 0

安全: 0

星星: 3

关注者: 2

分支: 2

开放问题: 0

类型:symfony-bundle

v1.0.0 2012-06-29 16:08 UTC

This package is not auto-updated.

Last update: 2022-02-01 12:20:55 UTC


README

跟踪您的Symfony2应用版本。了解应用在预发布/生产环境中的构建/版本号非常重要。

许多项目都有由开发者或CI服务器创建的VERSION或BUILD文件。此包提供了一个块、twig函数和Web调试工具栏面板,用于输出应用和Symfony的版本。版本在整个项目中作为服务可用。您可以将当前版本注入到生产环境的meta标签中。

安装

  1. 通过composer安装此包
{
    "require": {
        // ...
        "zenstruck/version-bundle": "dev-master"
    }
}
  1. 在项目的根目录下创建一个VERSION文件

  2. 配置此包

     # 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() }}" />
...

扩展

使用您自己的版本数据收集器

  1. 覆盖默认的VersionDataCollector

     // MyVersion.php
     use Zenstruck\Bundle\VersionBundle\DataCollector\VersionDataCollector;
    
     class MyVersion extends VersionDataCollector
     {
         public function getVersion()
         {
             return $myversion;
         }
     }
    
  2. 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