Skip to content

Commit

Permalink
2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
doyouhaobaby committed Dec 1, 2024
1 parent f06b066 commit 9487990
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 69 deletions.
13 changes: 1 addition & 12 deletions app/Controller/Home/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,6 @@ class Index
*/
public function handle(): string
{
// go(function() {
// //sleep(100);
// //sleep(10);
//// $fp = fopen('data.txt', 'a');//opens file in append mode
//// fwrite($fp, '23424');
//// fclose($fp);
//
// // echo "File appended successfully";
// });
// return '3332222223';

return View::display('home');
return View::proxy()->display('home');
}
}
46 changes: 46 additions & 0 deletions app/Infra/Helper/ForceCloseDebug.php
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);
}
}
47 changes: 0 additions & 47 deletions app/Infra/Provider/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@

namespace App\Infra\Provider;

use App\Infra\Module\Auth\Permission;
use App\Infra\Module\Auth\PermissionCache;
use Godruoyi\Snowflake\RedisSequenceResolver;
use Godruoyi\Snowflake\Snowflake;
use Leevel\Di\IContainer;
use Leevel\Di\Provider;

/**
Expand All @@ -21,9 +16,6 @@ class App extends Provider
*/
public function register(): void
{
$this->permission();
$this->redisSequence();
$this->snowflake();
}

/**
Expand All @@ -32,7 +24,6 @@ public function register(): void
public static function providers(): array
{
return [
'permission',
'redis_sequence',
'snowflake',
];
Expand All @@ -52,42 +43,4 @@ public static function isDeferred(): bool
public function bootstrap(): void
{
}

/**
* 注册 permission 服务.
*/
private function permission(): void
{
$this->container->bind('permission', function (IContainer $container): Permission {
/** @var \Leevel\Http\Request $request */
$request = $container->make('request');
$token = $request->query->get('token', $request->request->get('token', ''));

// @phpstan-ignore-next-line
return new Permission($container->make(PermissionCache::class), $token);
});
}

private function redisSequence(): void
{
$this->container->singleton('redis_sequence', function (IContainer $container): RedisSequenceResolver {
$redis = redis_cache();

return (new RedisSequenceResolver($redis))->setCachePrefix('redis_sequence:');
});
}

private function snowflake(): void
{
$this->container->singleton('snowflake', function (IContainer $container): Snowflake {
$redis = redis_cache();
$redisSequence = (new RedisSequenceResolver($redis))->setCachePrefix('snowflake_redis_sequence:');

return (new Snowflake(1, 1))
// 1678032000000 = 2023-03-06
->setStartTimeStamp(1678032000000)
->setSequenceResolver($redisSequence)
;
});
}
}
12 changes: 2 additions & 10 deletions app/Infra/Provider/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace App\Infra\Provider;

use App\Auth\Middleware\Auth;
use Leevel\Router\RouterProvider;
use Leevel\Session\Middleware\Session;

Expand Down Expand Up @@ -45,7 +44,6 @@ class Router extends RouterProvider
* - 例外在应用执行结束后响应环节也会调用 HTTP 中间件.
*/
protected array $middlewareAlias = [
'auth' => Auth::class,
'session' => Session::class,
];

Expand All @@ -56,12 +54,6 @@ class Router extends RouterProvider
'api/demo' => [
'middlewares' => 'api',
],
'apiQL/v*' => [
'middlewares' => 'auth',
],
'/app:*/apiQL/v*' => [
'middlewares' => 'auth',
],
];

/**
Expand All @@ -71,10 +63,10 @@ class Router extends RouterProvider
'pet' => [],
'store' => [],
'user' => [],
'/apiQL/v1' => [
'/api/v1' => [
'middlewares' => 'api',
],
'apiQL/v2' => [
'api/v2' => [
'middlewares' => 'api',
],
'/web/v1' => [
Expand Down

0 comments on commit 9487990

Please sign in to comment.