-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f06b066
commit 9487990
Showing
4 changed files
with
49 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Infra\Helper; | ||
|
||
use Leevel\Config\Proxy\Config; | ||
use Leevel\Debug\Debug; | ||
|
||
/** | ||
* 强制关闭调试模式. | ||
*/ | ||
class ForceCloseDebug | ||
{ | ||
protected static bool $debug = false; | ||
|
||
protected static bool $debugBar = false; | ||
|
||
public static function handle(): void | ||
{ | ||
static::$debug = (bool) Config::proxy()->get('debug'); | ||
Config::proxy()->set('debug', false); | ||
|
||
$debugBar = static::getDebugBar(); | ||
static::$debugBar = $debugBar->getDebugStatus(); | ||
$debugBar->disable(); | ||
} | ||
|
||
public static function restore(): void | ||
{ | ||
Config::set('debug', static::$debug); | ||
|
||
$debugBar = static::getDebugBar(); | ||
if (static::$debugBar) { | ||
$debugBar->enable(); | ||
} else { | ||
$debugBar->disable(); | ||
} | ||
} | ||
|
||
protected static function getDebugBar(): Debug | ||
{ | ||
// @phpstan-ignore-next-line | ||
return \App::proxy()->make(Debug::class); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters