Skip to content

Commit

Permalink
增加应用下线提醒 #3250
Browse files Browse the repository at this point in the history
  • Loading branch information
twinh committed Mar 21, 2017
1 parent e1203e4 commit fefba4b
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
30 changes: 30 additions & 0 deletions src/Middleware/CheckAppStatus.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace Miaoxing\App\Middleware;

use Miaoxing\Plugin\Middleware\Base;
use Miaoxing\Plugin\Service\AppRecord;
use Wei\RetTrait;

class CheckAppStatus extends Base
{
use RetTrait;

/**
* {@inheritdoc}
*/
public function __invoke($next)
{
// 超级管理员下线也可以访问,以便进行功能调整
if (wei()->curUser->isSuperAdmin()) {
return $next();
}

$record = $this->app->getRecord();
if (isset($record['status']) && $record['status'] != AppRecord::STATUS_ONLINE) {
return $this->err('很抱歉,该应用已经' . $record->getConstantValue('status', $record['status'], 'text'));
}

return $next();
}
}
20 changes: 19 additions & 1 deletion src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace Miaoxing\App;

use Miaoxing\App\Middleware\CheckAppStatus;
use miaoxing\plugin\BaseController;

class Plugin extends \miaoxing\plugin\BasePlugin
{
protected $name = '核心';
Expand Down Expand Up @@ -59,8 +62,23 @@ public function onPostPageCss()

/**
* 限制命令行控制器,只有在命令行下或超级管理员才可以访问
*
* @param BaseController $controller
*/
public function onControllerInit(BaseController $controller)
{
// 除去 admin/login 页面
if (substr($this->app->getController(), 0, 6) === 'admin/') {
$controller->middleware(CheckAppStatus::className());
}

$this->checkCli();
}

/**
* @todo 作为middleware
*/
public function onControllerInit()
protected function checkCli()
{
if (substr($this->app->getController(), 0, 4) !== 'cli/') {
return;
Expand Down

0 comments on commit fefba4b

Please sign in to comment.