insolita/yii2-maintenance

维护模式行为组件,专注于从外部配置中检索状态

安装次数: 10

依赖项: 0

建议者: 0

安全: 0

星星: 4

关注者: 2

分支: 1

开放问题: 0

类型:yii2-extension

0.0.1 2017-06-01 00:12 UTC

This package is auto-updated.

Last update: 2024-09-11 16:41:35 UTC


README

  • 维护模式行为组件,专注于从外部配置中检索状态
  • 支持在维护模式下允许对指定IPs的独占访问
  • 支持即将进行维护工作的初步通知
  • 提供维护过程或初步模式时的可观察事件

Status

安装

安装此扩展的首选方式是通过 composer

运行以下命令之一

composer require --prefer-dist insolita/yii2-maintenance "~0.0.1"

或者

"insolita/yii2-maintenance": "~0.0.1"

将以下内容添加到您的 composer.json 文件的 require 部分。

使用方法

安装扩展后,将其添加到 config 组件部分,以及 bootstrap 部分

     'bootstrap'=>['log','config','maintenance'],
     'container'=>[
     ...
         'definitions'=>[
             '\insolita\maintenance\IConfig'=>'your\config\component\class'
         ]
     ],
     ...
     'components'=>[
          'maintenance'=>[
              'class'=>'\insolita\maintenance\Maintenance',
              'enabledKey'=>'config key for maintennce indication',
              'preliminarKey'=>'config key for preliminar maintenance indication',
              'ipSkippedKey'=>'config key for comma-seperated ips with exclusive access',
              'catchRoute'=>['site/maintenance'], //- route catched all requests in maintenance mode
              //possible events use cases
              'on maintenance_process'=>function($event){
                  //$event->sender is maintenance component!
                  if($event->sender->isSkipForIp===true){
                     Yii::$app->getSession()->setFlash('warning','Site in maintenance mode!');
                  }
              },
              'on maintenance_soon'=>function($event){
                  Yii::$app->getSession()->setFlash('warning',
                  'After 5 minutes, the site will be serviced, please finish or save the undelivered messages');
               }
          ]
     ],