erfans/maintenance-bundle

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

一个用于允许网站维护模式的Symfony包。

安装: 16

依赖者: 0

建议者: 0

安全: 0

星星: 1

关注者: 2

分支: 0

开放问题: 0

类型:symfony-bundle

2.1.0 2019-12-30 11:44 UTC

This package is auto-updated.

Last update: 2022-03-29 00:34:23 UTC


README

A bundle to add maintenance mode to Symfony projects.

安装

第1步:下载包

打开命令行,进入您的项目目录,并执行以下命令以下载此包的最新稳定版本

$ composer require erfans/maintenance-bundle "~2.1"

此命令要求您已全局安装Composer,如Composer文档中的安装章节所述。

第2步:启用包

然后,通过将其添加到项目中app/AppKernel.php文件中注册的包列表来启用该包。

<?php
// app/AppKernel.php

// ...
class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            // ...

            new Erfans\MaintenanceBundle\ErfansMaintenanceBundle(),
        );

        // ...
    }

    // ...
}

第3步:添加路由

将维护默认控制器路由添加到app/config/routing.yml

erfans_maintenance:
    resource: "@ErfansMaintenanceBundle/Resources/config/routing.yml"

如果您想使用自己的控制器和动作来显示维护页面或使用外部链接,或者只想显示一个HTML页面,则可以跳过此部分。

第4步:配置

为了检查当前请求是否处于维护状态,此包将在包配置中检查定义的“包含/排除”规则列表。此方法将提供最大的灵活性,以便将网站的一部分置于维护模式,或者仅排除某些页面。

要添加“包含”规则,将参数“rule”设置为“+”,要添加排除规则,将“rule”设置为“-”。每个规则的可用参数包括

rule: # One of "+"; "-", Required
env:  # Requested environment e.g. "test" or ["dev", "prod"]
path: # Regular expression for request path e.g. ^/* to cover all requests
routes: # To compair with requested route e.g. ["home_route"]
host: # Requested host
schemes: # e.g. http or https 
methods: # Requested method e.g. ["get", "post"]
usernames: # Username of the current user            
roles: # Roles of the current user               
ips: # IP of the visitor                

默认规则是

rules:
    - {rule: '+', path: '^/*'} # include all paths into maintenance mode
    - {rule: '-', path: '^/login$'} # exclude usual path for login from the maintenance
    - {rule: '-', roles: ['ROLE_ADMIN']} # exclude Admin role from the maintenance
    - {rule: '-', env: ['test', 'dev']} # exclude environments "test" and "dev" from the maintenance 

定义规则可能看起来过于繁琐,但对于您想要在不干扰其他部分的情况下开发网站的新部分来说,它是非常方便的。

“ErfansMaintenanceBundle”的默认配置

erfans_maintenance:
    enabled:              false

    # After due-date maintenance mode will not invoke anymore. Date format should be 'YYYY-MM-DD' or 'YYYY-MM-DD HH:MM:SS' or 'YYYY-MM-DD HH:MM:SS +/-TT:TT' or timestamp
    due_date:             null # Example: 2016-7-6 or 2016-7-6 10:10 or 2016-7-6 10:10:10 +02:00 or 1467763200

    # It is possible to change corresponding controller by changing the route name.
    maintenance_route:    erfans_maintenance_maintenance

    # Maintenance page can be an external link or only an html page.
    maintenance_url:      ~

    # View parameters will set on default twig template of maintenance bundle. These values will translate before rendering
    view:
        title:                erfans.maintenance.messages.under_construction.title
        description:          erfans.maintenance.messages.under_construction.description

    # To provide maximum flexibility to put part of website on maintenance mode by defining 'include' or 'exclude' rules.
    rules:                # Example: - {rule: '+', path: '^/*'} # to set maintenance mode for whole website
        - {rule: '+', path: '^/*'}           # include all paths into maintenance mode
        - {rule: '-', path: '^/login$'}      # exclude usual path for login from maintenance
        - {rule: '-', roles: ['ROLE_ADMIN']} # exclude Admin role from maintenance
        - {rule: '-', env: ['test', 'dev']}  # exclude environments "test" and "dev" from maintenance

    # By enabling "redirect_on_normal" website will redirect from maintenance page if maintenance mode is disabled.
    redirect_on_normal:
        enabled:              true

        # Application will redirect from maintenance page to this url if maintenance_mode is false. You can only set one of redirect_url or redirect_route
        redirect_url:         /
        redirect_route:       ~