rkljw преди 3 седмици
родител
ревизия
667643957c

+ 0 - 28
app/Controller/PageController.php

@@ -1,28 +0,0 @@
-<?php
-
-declare(strict_types=1);
-
-namespace App\Controller;
-
-use Hyperf\HttpServer\Annotation\Controller;
-use Hyperf\HttpServer\Annotation\GetMapping;
-use Hyperf\View\RenderInterface;
-
-//#[Controller(prefix: "page")]
-class PageController
-{
-//    #[GetMapping(path: "home")]
-    public function index(RenderInterface $render)
-    {
-        var_dump("======###");
-
-        return $render->render('index', [
-            'title' => '页面标题',
-            'shared_data' => [
-                'app_name' => 'My App',
-                'current_year' => date('Y')
-            ],
-            // 其他页面特定变量...
-        ]);
-    }
-}

+ 17 - 0
app/Controller/ViewController.php

@@ -0,0 +1,17 @@
+<?php
+
+declare(strict_types=1);
+
+namespace App\Controller;
+
+use Hyperf\HttpServer\Annotation\AutoController;
+use Hyperf\View\RenderInterface;
+
+#[AutoController]
+class ViewController
+{
+    public function index(RenderInterface $render)
+    {
+        return $render->render('index', ['name' => 'Hyperf']);
+    }
+}

+ 66 - 66
app/Listener/DbQueryExecutedListener.php

@@ -1,66 +1,66 @@
-<?php
-
-declare(strict_types=1);
-/**
- * This file is part of Hyperf.
- *
- * @link     https://www.hyperf.io
- * @document https://hyperf.wiki
- * @contact  group@hyperf.io
- * @license  https://github.com/hyperf/hyperf/blob/master/LICENSE
- */
-
-namespace App\Listener;
-
-use Hyperf\Collection\Arr;
-use Hyperf\Database\Events\QueryExecuted;
-use Hyperf\Event\Annotation\Listener;
-use Hyperf\Event\Contract\ListenerInterface;
-use Hyperf\Logger\LoggerFactory;
-use Psr\Container\ContainerInterface;
-use Psr\Log\LoggerInterface;
-
-#[Listener]
-class DbQueryExecutedListener implements ListenerInterface
-{
-    /**
-     * @var LoggerInterface
-     */
-    private $logger;
-
-    public function __construct(ContainerInterface $container)
-    {
-        $this->logger = $container->get(LoggerFactory::class)->get('sql');
-    }
-
-    public function listen(): array
-    {
-        return [
-            QueryExecuted::class,
-        ];
-    }
-
-    /**
-     * @param QueryExecuted $event
-     */
-    public function process(object $event): void
-    {
-        if ($event instanceof QueryExecuted) {
-            $sql = $event->sql;
-            if (! Arr::isAssoc($event->bindings)) {
-                $position = 0;
-                foreach ($event->bindings as $value) {
-                    $position = strpos($sql, '?', $position);
-                    if ($position === false) {
-                        break;
-                    }
-                    $value = "'{$value}'";
-                    $sql = substr_replace($sql, $value, $position, 1);
-                    $position += strlen($value);
-                }
-            }
-
-            $this->logger->info(sprintf('[%s] %s', $event->time, $sql));
-        }
-    }
-}
+<?php
+
+declare(strict_types=1);
+/**
+ * This file is part of Hyperf.
+ *
+ * @link     https://www.hyperf.io
+ * @document https://hyperf.wiki
+ * @contact  group@hyperf.io
+ * @license  https://github.com/hyperf/hyperf/blob/master/LICENSE
+ */
+
+namespace App\Listener;
+
+use Hyperf\Collection\Arr;
+use Hyperf\Database\Events\QueryExecuted;
+use Hyperf\Event\Annotation\Listener;
+use Hyperf\Event\Contract\ListenerInterface;
+use Hyperf\Logger\LoggerFactory;
+use Psr\Container\ContainerInterface;
+use Psr\Log\LoggerInterface;
+
+#[Listener]
+class DbQueryExecutedListener implements ListenerInterface
+{
+    /**
+     * @var LoggerInterface
+     */
+    private $logger;
+
+    public function __construct(ContainerInterface $container)
+    {
+        $this->logger = $container->get(LoggerFactory::class)->get('sql');
+    }
+
+    public function listen(): array
+    {
+        return [
+            QueryExecuted::class,
+        ];
+    }
+
+    /**
+     * @param QueryExecuted $event
+     */
+    public function process(object $event): void
+    {
+        if ($event instanceof QueryExecuted) {
+            $sql = $event->sql;
+            if (! Arr::isAssoc($event->bindings)) {
+                $position = 0;
+                foreach ($event->bindings as $value) {
+                    $position = strpos($sql, '?', $position);
+                    if ($position === false) {
+                        break;
+                    }
+                    $value = "'{$value}'";
+                    $sql = substr_replace($sql, $value, $position, 1);
+                    $position += strlen($value);
+                }
+            }
+
+            $this->logger->info(sprintf('[%s] %s', $event->time, $sql));
+        }
+    }
+}

+ 35 - 35
app/Listener/ResumeExitCoordinatorListener.php

@@ -1,35 +1,35 @@
-<?php
-
-declare(strict_types=1);
-/**
- * This file is part of Hyperf.
- *
- * @link     https://www.hyperf.io
- * @document https://hyperf.wiki
- * @contact  group@hyperf.io
- * @license  https://github.com/hyperf/hyperf/blob/master/LICENSE
- */
-
-namespace App\Listener;
-
-use Hyperf\Command\Event\AfterExecute;
-use Hyperf\Coordinator\Constants;
-use Hyperf\Coordinator\CoordinatorManager;
-use Hyperf\Event\Annotation\Listener;
-use Hyperf\Event\Contract\ListenerInterface;
-
-#[Listener]
-class ResumeExitCoordinatorListener implements ListenerInterface
-{
-    public function listen(): array
-    {
-        return [
-            AfterExecute::class,
-        ];
-    }
-
-    public function process(object $event): void
-    {
-        CoordinatorManager::until(Constants::WORKER_EXIT)->resume();
-    }
-}
+<?php
+
+declare(strict_types=1);
+/**
+ * This file is part of Hyperf.
+ *
+ * @link     https://www.hyperf.io
+ * @document https://hyperf.wiki
+ * @contact  group@hyperf.io
+ * @license  https://github.com/hyperf/hyperf/blob/master/LICENSE
+ */
+
+namespace App\Listener;
+
+use Hyperf\Command\Event\AfterExecute;
+use Hyperf\Coordinator\Constants;
+use Hyperf\Coordinator\CoordinatorManager;
+use Hyperf\Event\Annotation\Listener;
+use Hyperf\Event\Contract\ListenerInterface;
+
+#[Listener]
+class ResumeExitCoordinatorListener implements ListenerInterface
+{
+    public function listen(): array
+    {
+        return [
+            AfterExecute::class,
+        ];
+    }
+
+    public function process(object $event): void
+    {
+        CoordinatorManager::until(Constants::WORKER_EXIT)->resume();
+    }
+}

+ 32 - 0
app/Listener/TaskEventListener.php

@@ -0,0 +1,32 @@
+<?php
+
+declare(strict_types=1);
+
+namespace App\Listener;
+
+use Hyperf\Event\Annotation\Listener;
+use Hyperf\Event\Contract\ListenerInterface;
+use Hyperf\Framework\Event\BeforeMainServerStart;
+use Hyperf\Task\TaskExecutor;
+use Psr\Container\ContainerInterface;
+
+#[Listener]
+class TaskEventListener implements ListenerInterface
+{
+    public function __construct(private ContainerInterface $container)
+    {
+    }
+
+    public function listen(): array
+    {
+        return [
+            BeforeMainServerStart::class,
+        ];
+    }
+
+    public function process(object $event): void
+    {
+        $executor = $this->container->get(TaskExecutor::class);
+        $event->server->on('Task', [$executor, 'execute']);
+    }
+}

+ 26 - 0
app/Service/SmartyRenderer.php

@@ -0,0 +1,26 @@
+<?php
+namespace App\Service;
+
+use Hyperf\Context\ApplicationContext;
+use Smarty;
+
+class SmartyRenderer
+{
+    protected Smarty $smarty;
+
+    public function __construct()
+    {
+        $this->smarty = new Smarty();
+        $this->smarty->setTemplateDir(BASE_PATH . '/storage/view/');
+        $this->smarty->setCompileDir(BASE_PATH . '/runtime/smarty/compile/');
+        $this->smarty->setCacheDir(BASE_PATH . '/runtime/smarty/cache/');
+    }
+
+    public function render(string $template, array $data): string
+    {
+        foreach ($data as $key => $value) {
+            $this->smarty->assign($key, $value);
+        }
+        return $this->smarty->fetch($template);
+    }
+}

+ 35 - 16
app/View/Engine/SmartyEngine.php

@@ -11,19 +11,21 @@ use RuntimeException;
 class SmartyEngine implements EngineInterface
 {
     protected Smarty $smarty;
-    protected array $shared = [];
 
-    public function __construct()
+    public function __construct(array $options = [])
     {
         $this->smarty = new Smarty();
 
-        // 基础配置
-        $this->smarty->setLeftDelimiter('{{');
-        $this->smarty->setRightDelimiter('}}');
-        $this->smarty->setCompileDir(BASE_PATH . '/runtime/smarty/compile/');
-        $this->smarty->setCacheDir(BASE_PATH . '/runtime/smarty/cache/');
-        $this->smarty->setTemplateDir(BASE_PATH . '/storage/view/');
+        // 设置模板目录
+        $this->smarty->setTemplateDir($options['template_dir'] ?? BASE_PATH . '/storage/view/');
+        $this->smarty->setCompileDir($options['compile_dir'] ?? BASE_PATH . '/runtime/smarty/compile/');
+        $this->smarty->setCacheDir($options['cache_dir'] ?? BASE_PATH . '/runtime/smarty/cache/');
 
+        // 设置定界符
+        $this->smarty->setLeftDelimiter($options['left_delimiter'] ?? '{{');
+        $this->smarty->setRightDelimiter($options['right_delimiter'] ?? '}}');
+
+        // 确保目录存在
         $this->ensureDirectoryExists($this->smarty->getCompileDir());
         $this->ensureDirectoryExists($this->smarty->getCacheDir());
     }
@@ -35,24 +37,41 @@ class SmartyEngine implements EngineInterface
         }
     }
 
-    public function share(string $key, $value): void
-    {
-        $this->shared[$key] = $value;
-    }
-
     public function render(string $template, array $data, array $config): string
     {
-        // 合并共享变量
-        $data = array_merge($this->shared, $data);
+        // 标准化模板路径
+        $template = $this->normalizeTemplatePath($template);
+
+        // 获取完整模板路径
+        $templatePath = $this->smarty->getTemplateDir()[0] . $template;
 
+        // 检查模板文件是否存在
+        if (!file_exists($templatePath)) {
+            throw new RuntimeException("Template file not found: {$templatePath}");
+        }
+
+        // 分配变量
         foreach ($data as $key => $value) {
             $this->smarty->assign($key, $value);
         }
 
         try {
-            return $this->smarty->fetch($template);
+            return $this->smarty->fetch($templatePath);
         } catch (\SmartyException $e) {
             throw new RuntimeException("Smarty render failed: " . $e->getMessage());
         }
     }
+
+    protected function normalizeTemplatePath(string $path): string
+    {
+        // 移除可能的绝对路径前缀
+        $path = str_replace(BASE_PATH, '', $path);
+        // 移除开头的斜杠
+        $path = ltrim($path, '/');
+        // 确保使用正确的扩展名
+        if (!str_ends_with($path, '.tpl')) {
+            $path .= '.tpl';
+        }
+        return $path;
+    }
 }

+ 14 - 0
app/View/Render/SmartyRender.php

@@ -0,0 +1,14 @@
+<?php
+namespace App\View\Render;
+
+use Hyperf\View\Render;
+use App\View\Engine\SmartyEngine;
+
+class SmartyRender extends Render
+{
+    public function getEngine(): SmartyEngine
+    {
+        return $this->engine;
+    }
+
+}

+ 0 - 42
config/autoload/amqp.php

@@ -1,42 +0,0 @@
-<?php
-
-declare (strict_types = 1);
-use function Hyperf\Support\env;
-return [
-    'enable' => true,
-    'default' => [
-        'host' => env('AMQP_HOST', '192.168.1.127'),
-        'port' => (int) env('AMQP_PORT', 5672),
-        'user' => env('AMQP_USER', 'guest'),
-        'password' => env('AMQP_PASSWORD', 'guest'),
-        'vhost' => '/',
-        'concurrent' => [
-            'limit' => 1,
-        ],
-        'pool' => [
-            'min_connections' => 1,
-            'max_connections' => 1, // 限制最大连接数为1
-            'connect_timeout' => 10.0,
-            'wait_timeout' => 3.0,
-            'heartbeat' => -1,
-            
-        ],
-        'params' => [
-            'insist' => false,
-            'login_method' => 'AMQPLAIN',
-            'login_response' => null,
-            'locale' => 'en_US',
-            'connection_timeout' => 3.0,
-            // 尽量保持是 heartbeat 数值的两倍
-            'read_write_timeout' => 6.0,
-            'context' => null,
-            'keepalive' => false,
-            // 尽量保证每个消息的消费时间小于心跳时间
-            'heartbeat' => 3,
-            'close_on_destruct' => false,
-        ],
-    ],
-    'pool2' => [
-
-    ],
-];

+ 0 - 21
config/autoload/annotations.php

@@ -1,21 +0,0 @@
-<?php
-
-declare(strict_types=1);
-/**
- * This file is part of Hyperf.
- *
- * @link     https://www.hyperf.io
- * @document https://hyperf.wiki
- * @contact  group@hyperf.io
- * @license  https://github.com/hyperf/hyperf/blob/master/LICENSE
- */
-return [
-    'scan' => [
-        'paths' => [
-            BASE_PATH . '/app',
-        ],
-        'ignore_annotations' => [
-            'mixin',
-        ],
-    ],
-];

+ 0 - 13
config/autoload/aspects.php

@@ -1,13 +0,0 @@
-<?php
-
-declare(strict_types=1);
-/**
- * This file is part of Hyperf.
- *
- * @link     https://www.hyperf.io
- * @document https://hyperf.wiki
- * @contact  group@hyperf.io
- * @license  https://github.com/hyperf/hyperf/blob/master/LICENSE
- */
-return [
-];

+ 0 - 44
config/autoload/async_queue.php

@@ -1,44 +0,0 @@
-<?php
-
-declare(strict_types=1);
-/**
- * This file is part of Hyperf.
- *
- * @link     https://www.hyperf.io
- * @document https://hyperf.wiki
- * @contact  group@hyperf.io
- * @license  https://github.com/hyperf/hyperf/blob/master/LICENSE
- */
-use Hyperf\AsyncQueue\Driver\RedisDriver;
-
-return [
-    'default' => [
-        'driver' => RedisDriver::class,
-        'redis' => [
-            'pool' => 'default',
-        ],
-        'channel' => '{gatherList}',
-        'timeout' => 2,
-        'retry_seconds' => 5,
-        'handle_timeout' => 10,
-        'processes' => 1,
-        'concurrent' => [
-            'limit' => 10,
-        ],
-        'max_messages' => 0,
-    ],
-    'import' => [
-        'driver' => RedisDriver::class,
-        'redis' => [
-            'pool' => 'default'
-        ],
-        'channel' => '{importList}',
-        'timeout' => 2,
-        'retry_seconds' => 5,
-        'handle_timeout' => 10,
-        'processes' => 1,
-        'concurrent' => [
-            'limit' => 5,
-        ],
-    ],
-];

+ 0 - 19
config/autoload/cache.php

@@ -1,19 +0,0 @@
-<?php
-
-declare(strict_types=1);
-/**
- * This file is part of Hyperf.
- *
- * @link     https://www.hyperf.io
- * @document https://hyperf.wiki
- * @contact  group@hyperf.io
- * @license  https://github.com/hyperf/hyperf/blob/master/LICENSE
- */
-return [
-    'default' => [
-        'driver' => Hyperf\Cache\Driver\RedisDriver::class,
-        'packer' => Hyperf\Codec\Packer\PhpSerializerPacker::class,
-        'prefix' => 'c:',
-        'skip_cache_results' => [],
-    ],
-];

+ 0 - 13
config/autoload/commands.php

@@ -1,13 +0,0 @@
-<?php
-
-declare(strict_types=1);
-/**
- * This file is part of Hyperf.
- *
- * @link     https://www.hyperf.io
- * @document https://hyperf.wiki
- * @contact  group@hyperf.io
- * @license  https://github.com/hyperf/hyperf/blob/master/LICENSE
- */
-return [
-];

+ 0 - 19
config/autoload/config_center.php

@@ -1,19 +0,0 @@
-<?php
-
-declare(strict_types=1);
-/**
- * This file is part of Hyperf.
- *
- * @link     https://www.hyperf.io
- * @document https://hyperf.wiki
- * @contact  group@hyperf.io
- * @license  https://github.com/hyperf/hyperf/blob/master/LICENSE
- */
-use Hyperf\ConfigCenter\Mode;
-
-use function Hyperf\Support\env;
-
-return [
-
-
-];

+ 0 - 41
config/autoload/databases.php

@@ -1,41 +0,0 @@
-<?php
-
-declare(strict_types=1);
-/**
- * This file is part of Hyperf.
- *
- * @link     https://www.hyperf.io
- * @document https://hyperf.wiki
- * @contact  group@hyperf.io
- * @license  https://github.com/hyperf/hyperf/blob/master/LICENSE
- */
-use function Hyperf\Support\env;
-
-return [
-    'default' => [
-        'driver' => env('DB_DRIVER', 'mysql'),
-        'host' => env('DB_HOST', 'localhost'),
-        'database' => env('DB_DATABASE', 'hyperf'),
-        'port' => env('DB_PORT', 3306),
-        'username' => env('DB_USERNAME', 'root'),
-        'password' => env('DB_PASSWORD', ''),
-        'charset' => env('DB_CHARSET', 'utf8'),
-        'collation' => env('DB_COLLATION', 'utf8_unicode_ci'),
-        'prefix' => env('DB_PREFIX', ''),
-        'pool' => [
-            'min_connections' => 1,
-            'max_connections' => 10,
-            'connect_timeout' => 10.0,
-            'wait_timeout' => 3.0,
-            'heartbeat' => -1,
-            'max_idle_time' => (float) env('DB_MAX_IDLE_TIME', 60),
-        ],
-        'commands' => [
-            'gen:model' => [
-                'path' => 'app/Model',
-                'force_casts' => true,
-                'inheritance' => 'Model',
-            ],
-        ],
-    ],
-];

+ 0 - 44
config/autoload/devtool.php

@@ -1,44 +0,0 @@
-<?php
-
-declare(strict_types=1);
-/**
- * This file is part of Hyperf.
- *
- * @link     https://www.hyperf.io
- * @document https://hyperf.wiki
- * @contact  group@hyperf.io
- * @license  https://github.com/hyperf/hyperf/blob/master/LICENSE
- */
-return [
-    'generator' => [
-        'amqp' => [
-            'consumer' => [
-                'namespace' => 'App\\Amqp\\Consumer',
-            ],
-            'producer' => [
-                'namespace' => 'App\\Amqp\\Producer',
-            ],
-        ],
-        'aspect' => [
-            'namespace' => 'App\\Aspect',
-        ],
-        'command' => [
-            'namespace' => 'App\\Command',
-        ],
-        'controller' => [
-            'namespace' => 'App\\Controller',
-        ],
-        'job' => [
-            'namespace' => 'App\\Job',
-        ],
-        'listener' => [
-            'namespace' => 'App\\Listener',
-        ],
-        'middleware' => [
-            'namespace' => 'App\\Middleware',
-        ],
-        'Process' => [
-            'namespace' => 'App\\Processes',
-        ],
-    ],
-];

+ 0 - 21
config/autoload/exceptions.php

@@ -1,21 +0,0 @@
-<?php
-
-declare(strict_types=1);
-/**
- * This file is part of Hyperf.
- *
- * @link     https://www.hyperf.io
- * @document https://hyperf.wiki
- * @contact  group@hyperf.io
- * @license  https://github.com/hyperf/hyperf/blob/master/LICENSE
- */
-return [
-    'handler' => [
-        'http' => [
-            Hyperf\Validation\ValidationExceptionHandler::class,
-            Hyperf\HttpServer\Exception\Handler\HttpExceptionHandler::class,
-            App\Exception\Handler\AppExceptionHandler::class,
-
-        ],
-    ],
-];

+ 0 - 108
config/autoload/jwt.php

@@ -1,108 +0,0 @@
-<?php
-declare(strict_types=1);
-use function Hyperf\Support\env;
-return [
-    /**
-     * 不需要检查的路由,如果使用jwt提供的默认中间件,可以对某些不用做检验的路由进行配置,例如登录等
-     * 具体的逻辑可以效仿JWT提供的默认中间件
-     * [
-     *      ["GET", "/index/test"],
-     *      ["**", "/test"]
-     * ]
-     *
-     * 第一个填写请求方法('**'代表支持所有的请求方法),第二个填写路由路径('/**'代表支持所有的路径)
-     * 如果数组中存在["**", "/**"],则默认所有的请求路由都不做jwt token的校验,直接放行,如果no_check_route为一个空数组,则
-     * 所有的请求路由都需要做jwt token校验
-     * 路由路径支持正则的写法
-     * 正则写法:["**", "/api/{name:.+}"]  支持模块化不做jwt token的校验,例如:/api/login/login
-     */
-    'no_check_route' => [
-//        ["**", "/api/{name:.+}"],
-    ],
-
-    'login_type' => env('JWT_LOGIN_TYPE', 'mpop'), //  登录方式,sso为单点登录,同一个用户只能登录一个端,mpop为多点登录
-
-    /**
-     * 单点登录自定义数据中必须存在uid的键值,这个key你可以自行定义,只要自定义数据中存在该键即可
-     */
-    'sso_key' => 'uid',
-
-    /**
-     * 只能用于Hmac包下的加密非对称算法,其它的都会使用公私钥
-     */
-    'secret' => env('JWT_SECRET', 'phper666'),
-
-    /**
-     * JWT 权限keys
-     * 对称算法: HS256, HS384 & HS512 使用 `JWT_SECRET`.
-     * 非对称算法: RS256, RS384 & RS512 / ES256, ES384 & ES512 使用下面的公钥私钥,需要自己去生成.
-     */
-    'keys' => [
-//        'public' => env('JWT_PUBLIC_KEY'), // 公钥,例如:'file:///path/to/public/key'
-//        'private' => env('JWT_PRIVATE_KEY'), // 私钥,例如:'file:///path/to/private/key'
-
-        /**
-         * 你的私钥的密码。不需要密码可以不用设置
-         */
-//        'passphrase' => env('JWT_PASSPHRASE'),
-    ],
-
-    'ttl' => env('JWT_TTL', 300), // token过期时间,单位为秒
-
-    /**
-     * 支持的对称算法:HS256、HS384、HS512
-     * 支持的非对称算法:RS256、RS384、RS512、ES256、ES384、ES512
-     */
-    'alg' => env('JWT_ALG', 'HS256'), // jwt的hearder加密算法
-
-    /**
-     * jwt使用到的缓存前缀
-     * 建议使用独立的redis做缓存,这样比较好做分布式
-     */
-    'cache_prefix' => 'phper666:jwt',
-
-    /**
-     * 是否开启黑名单,单点登录和多点登录的注销、刷新使原token失效,必须要开启黑名单,目前黑名单缓存只支持hyperf缓存驱动
-     */
-    'blacklist_enabled' => env('JWT_BLACKLIST_ENABLED', true),
-
-    /**
-     * 黑名单的宽限时间 单位为:秒,注意:如果使用单点登录,该宽限时间无效
-     */
-    'blacklist_grace_period' => env('JWT_BLACKLIST_GRACE_PERIOD', 0),
-
-    /**
-     * 签发者
-     */
-    'issued_by' => 'phper666/jwt',
-
-    /**
-     * 区分不同场景的token,比如你一个项目可能会有多种类型的应用接口鉴权,下面自行定义,我只是举例子
-     * 下面的配置会自动覆盖根配置,比如application1会里面的数据会覆盖掉根数据
-     * 下面的scene会和根数据合并
-     * scene必须存在一个default
-     * 什么叫根数据,这个配置的一维数组,除了scene都叫根配置
-     */
-    'scene' => [
-        'default' => [
-            'ttl' => 86400,
-        ],
-        'application' => [
-            'secret' => 'application', // 非对称加密使用字符串,请使用自己加密的字符串
-            'login_type' => 'sso', //  登录方式,sso为单点登录,mpop为多点登录
-            'sso_key' => 'uid',
-            'ttl' => 7200, // token过期时间,单位为秒
-        ],
-        'application1' => [
-            'secret' => 'application1', // 非对称加密使用字符串,请使用自己加密的字符串
-            'login_type' => 'sso', //  登录方式,sso为单点登录,mpop为多点登录
-            'sso_key' => 'uid',
-            'ttl' => 7200, // token过期时间,单位为秒
-        ],
-        'application2' => [
-            'secret' => 'application2', // 非对称加密使用字符串,请使用自己加密的字符串
-            'login_type' => 'mpop', //  登录方式,sso为单点登录,mpop为多点登录
-            'ttl' => 7200, // token过期时间,单位为秒
-        ]
-    ]
-];

+ 0 - 15
config/autoload/listeners.php

@@ -1,15 +0,0 @@
-<?php
-
-declare(strict_types=1);
-/**
- * This file is part of Hyperf.
- *
- * @link     https://www.hyperf.io
- * @document https://hyperf.wiki
- * @contact  group@hyperf.io
- * @license  https://github.com/hyperf/hyperf/blob/master/LICENSE
- */
-return [
-    Hyperf\ExceptionHandler\Listener\ErrorExceptionHandler::class,
-    Hyperf\Command\Listener\FailToHandleListener::class,
-];

+ 0 - 30
config/autoload/logger.php

@@ -1,30 +0,0 @@
-<?php
-
-declare(strict_types=1);
-/**
- * This file is part of Hyperf.
- *
- * @link     https://www.hyperf.io
- * @document https://hyperf.wiki
- * @contact  group@hyperf.io
- * @license  https://github.com/hyperf/hyperf/blob/master/LICENSE
- */
-return [
-    'default' => [
-        'handler' => [
-            'class' => Monolog\Handler\StreamHandler::class,
-            'constructor' => [
-                'stream' => BASE_PATH . '/runtime/logs/hyperf.log',
-                'level' => Monolog\Logger::DEBUG,
-            ],
-        ],
-        'formatter' => [
-            'class' => Monolog\Formatter\LineFormatter::class,
-            'constructor' => [
-                'format' => null,
-                'dateFormat' => 'Y-m-d H:i:s',
-                'allowInlineLineBreaks' => true,
-            ],
-        ],
-    ],
-];

+ 0 - 12
config/autoload/middlewares.php

@@ -1,12 +0,0 @@
-<?php
-return [
-    'http' => [
-        \App\Middleware\CorsMiddleware::class,
-//        \App\Middleware\Auth\SensitiveMiddleware::class,
-        \Hyperf\Validation\Middleware\ValidationMiddleware::class,
-//        App\Middleware\ViewShareMiddleware::class,
-    ],
-    'ws' => [
-        \App\Middleware\WebSocketAuthMiddleware::class
-    ]
-];

+ 0 - 14
config/autoload/processes.php

@@ -1,14 +0,0 @@
-<?php
-
-declare(strict_types=1);
-/**
- * This file is part of Hyperf.
- *
- * @link     https://www.hyperf.io
- * @document https://hyperf.wiki
- * @contact  group@hyperf.io
- * @license  https://github.com/hyperf/hyperf/blob/master/LICENSE
- */
-return [
-    Hyperf\AsyncQueue\Process\ConsumerProcess::class, //异步消费进程
-];

+ 0 - 6
config/autoload/providers.php

@@ -1,6 +0,0 @@
-<?php
-declare(strict_types=1);
-return [
-    // 这里添加你的服务提供者类名
-
-];

+ 0 - 57
config/autoload/redis.php

@@ -1,57 +0,0 @@
-<?php
-
-declare(strict_types=1);
-/**
- * This file is part of Hyperf.
- *
- * @link     https://www.hyperf.io
- * @document https://hyperf.wiki
- * @contact  group@hyperf.io
- * @license  https://github.com/hyperf/hyperf/blob/master/LICENSE
- */
-use function Hyperf\Support\env;
-
-return [
-    'default' => [
-        'host' => env('REDIS_HOST', '127.0.0.1'),
-        'auth' => env('REDIS_AUTH', '123456'),
-        'port' => (int) env('REDIS_PORT', 6379),
-        'db' => (int) env('REDIS_DB', 0),
-        'pool' => [
-            'min_connections' => 1,
-            'max_connections' => 100,
-            'connect_timeout' => 100000000.0,
-            'wait_timeout' => 30000000.0,
-            'heartbeat' => -1,
-            'max_idle_time' => (float) env('REDIS_MAX_IDLE_TIME', 6000000000),
-        ],
-        'driver' => Hyperf\AsyncQueue\Driver\RedisDriver::class,
-        'redis' => [
-            'pool' => 'default'
-        ],
-        'channel' => '{queue:import}',
-        'timeout' => 20,
-        'retry_seconds' => 5,
-        'handle_timeout' => 10,
-        'processes' => 100,
-        'concurrent' => [
-            'limit' => 10000,
-        ],
-        'max_messages' => 0,
-    ],
-    'import' => [
-        'driver' => Hyperf\AsyncQueue\Driver\RedisDriver::class,
-        'redis' => [
-            'pool' => 'default'
-        ],
-        'channel' => '{queue:import}',
-        'timeout' => 20,
-        'retry_seconds' => 5,
-        'handle_timeout' => 10,
-        'processes' => 100,
-        'concurrent' => [
-            'limit' => 10000,
-        ],
-        'max_messages' => 0,
-    ],
-];

+ 0 - 63
config/autoload/server.php

@@ -1,63 +0,0 @@
-<?php
-
-declare(strict_types=1);
-/**
- * This file is part of Hyperf.
- *
- * @link     https://www.hyperf.io
- * @document https://hyperf.wiki
- * @contact  group@hyperf.io
- * @license  https://github.com/hyperf/hyperf/blob/master/LICENSE
- */
-use Hyperf\Server\Event;
-use Hyperf\Server\Server;
-use Swoole\Constant;
-
-return [
-    'mode' => SWOOLE_PROCESS,
-    'servers' => [
-        [
-            'name' => 'http',
-            'type' => Server::SERVER_HTTP,
-            'host' => '0.0.0.0',
-            'port' => 9501,
-            'sock_type' => SWOOLE_SOCK_TCP,
-            'callbacks' => [
-                Event::ON_REQUEST => [App\Service\Server\StreamServer::class, 'onRequest'],
-//                Event::ON_REQUEST => [Hyperf\HttpServer\Server::class, 'onRequest'],
-            ],
-        ],
-        [
-            'name' => 'ws',
-            'type' => Server::SERVER_WEBSOCKET,
-            'host' => '0.0.0.0',
-            'port' => 9506,
-            'sock_type' => SWOOLE_SOCK_TCP,
-            'callbacks' => [
-                Event::ON_HAND_SHAKE => [Hyperf\WebSocketServer\Server::class, 'onHandShake'],
-                Event::ON_MESSAGE => [Hyperf\WebSocketServer\Server::class, 'onMessage'],
-                Event::ON_CLOSE => [Hyperf\WebSocketServer\Server::class, 'onClose'],
-            ],
-        ],
-    ],
-    'settings' => [
-        'document_root' => BASE_PATH . '/public',
-        'enable_static_handler' => true,
-        Constant::OPTION_ENABLE_COROUTINE => true,
-        Constant::OPTION_WORKER_NUM => swoole_cpu_num(),
-        Constant::OPTION_PID_FILE => BASE_PATH . '/runtime/hyperf.pid',
-        Constant::OPTION_OPEN_TCP_NODELAY => true,
-        Constant::OPTION_MAX_COROUTINE => 10 * 1024 * 1024,
-        Constant::OPTION_OPEN_HTTP2_PROTOCOL => true,
-        Constant::OPTION_MAX_REQUEST => 10 * 1024 * 1024,
-        Constant::OPTION_SOCKET_BUFFER_SIZE => 10 * 1024 * 1024,
-        Constant::OPTION_BUFFER_OUTPUT_SIZE => 10 * 1024 * 1024,
-        Constant::OPTION_UPLOAD_MAX_FILESIZE => 10 * 1024 * 1024,
-    ],
-    'callbacks' => [
-        Event::ON_WORKER_START => [Hyperf\Framework\Bootstrap\WorkerStartCallback::class, 'onWorkerStart'],
-        Event::ON_PIPE_MESSAGE => [Hyperf\Framework\Bootstrap\PipeMessageCallback::class, 'onPipeMessage'],
-        Event::ON_WORKER_EXIT => [Hyperf\Framework\Bootstrap\WorkerExitCallback::class, 'onWorkerExit'],
-    ],
-
-];

+ 0 - 127
config/autoload/services.php

@@ -1,127 +0,0 @@
-<?php
-
-return [
-    'consumers' => [
-        [
-            // 用戶中心
-            'name' => 'UserService',
-            'service' => \App\JsonRpc\UserServiceInterface::class,
-            // 直接对指定的节点进行消费,通过下面的 nodes 参数来配置服务提供者的节点信息
-            'nodes' => [
-                ['host' => '127.0.0.1', 'port' => 9504],
-            ],
-        ],
-        [
-            // 权限管理
-            'name' => 'AuthorityService',
-            'service' => \App\JsonRpc\AuthorityServiceInterface::class,
-            // 直接对指定的节点进行消费,通过下面的 nodes 参数来配置服务提供者的节点信息
-            'nodes' => [
-                ['host' => '127.0.0.1', 'port' => 9504],
-            ],
-        ],
-        [
-            // 广告中心
-            'name' => 'AdService',
-            'service' => \App\JsonRpc\AdServiceInterface::class,
-            // 直接对指定的节点进行消费,通过下面的 nodes 参数来配置服务提供者的节点信息
-            'nodes' => [
-                ['host' => '127.0.0.1', 'port' => 9503],
-            ],
-        ],
-        [
-            //网站管理
-            'name' => 'WebsiteService',
-            'service' => \App\JsonRpc\WebsiteServiceInterface::class,
-            // 直接对指定的节点进行消费,通过下面的 nodes 参数来配置服务提供者的节点信息
-            'nodes' => [
-                ['host' => '127.0.0.1', 'port' => 9502],
-            ],
-        ],
-        [
-            //公共方法
-            'name' => 'PublicRpcService',
-            'service' => \App\JsonRpc\PublicRpcServiceInterface::class,
-            // 直接对指定的节点进行消费,通过下面的 nodes 参数来配置服务提供者的节点信息
-            'nodes' => [
-                ['host' => '127.0.0.1', 'port' => 9502],
-            ],
-            'settings' => [
-                'open_length_check' => true,
-                'package_max_length' => 15 * 1024 * 1024, // 最大包长度
-                'package_length_type' => 'N',
-                'package_body_offset' => 8,
-                'package_length_offset' => 4,
-                'package_length_field' => 'length',
-            ],
-            'options' => [
-                'connect_timeout' => 50.0, // 连接超时时间,单位为秒
-                'read_timeout' => 100.0, // 读取超时时间,单位为秒
-                'write_timeout' => 100.0, // 写入超时时间,单位为秒
-            ],
-            'pool' => [
-                'min_connections' => 1,
-                'max_connections' => 30,
-                'connect_timeout' => 100.0, // 连接池连接超时时间,单位为秒
-                'wait_timeout' => 30.0, // 等待连接池可用连接的超时时间,单位为秒
-                'heartbeat' => -1, // 心跳检测间隔,-1 表示禁用心跳检测
-                'max_idle_time' => 60.0, // 连接的最大空闲时间,单位为秒
-            ],
-        ],
-        [
-            //资讯-新闻
-            'name' => 'NewsService',
-            'service' => \App\JsonRpc\NewsServiceInterface::class,
-            // 直接对指定的节点进行消费,通过下面的 nodes 参数来配置服务提供者的节点信息
-            'nodes' => [
-                ['host' => '127.0.0.1', 'port' => 9505],
-            ],
-        ],
-        [
-            //友情链接服务
-            'name' => 'LinkService',
-            'service' => \App\JsonRpc\LinkServiceInterface::class,
-            // 直接对指定的节点进行消费,通过下面的 nodes 参数来配置服务提供者的节点信息
-            'nodes' => [
-                ['host' => '127.0.0.1', 'port' => 9502],
-            ],
-        ],
-        [
-            //商圈服务
-            'name' => 'ChatService',
-            'service' => \App\JsonRpc\ChatServiceInterface::class,
-            // 直接对指定的节点进行消费,通过下面的 nodes 参数来配置服务提供者的节点信息
-            'nodes' => [
-                ['host' => '127.0.0.1', 'port' => 9507],
-            ],
-        ],
-        [
-            //广告订单服务
-            'name' => 'OrderService',
-            'service' => \App\JsonRpc\OrderServiceInterface::class,
-            // 直接对指定的节点进行消费,通过下面的 nodes 参数来配置服务提供者的节点信息
-            'nodes' => [
-                ['host' => '127.0.0.1', 'port' => 9508],
-            ],
-        ],
-        [
-            //采集器服务
-            'name' => 'CollectorService',
-            'service' => \App\JsonRpc\CollectorServiceInterface::class,
-
-            // 直接对指定的节点进行消费,通过下面的 nodes 参数来配置服务提供者的节点信息
-            'nodes' => [
-                ['host' => '127.0.0.1', 'port' => 9509],
-            ],
-        ],
-        [
-            //底部导航服务
-            'name' => 'FooterService',
-            'service' => \App\JsonRpc\FooterServiceInterface::class,
-            // 直接对指定的节点进行消费,通过下面的 nodes 参数来配置服务提供者的节点信息
-            'nodes' => [
-                ['host' => '127.0.0.1', 'port' => 9502],
-            ],
-        ],
-    ],
-];

+ 0 - 23
config/autoload/snowflake.php

@@ -1,23 +0,0 @@
-<?php
-
-declare(strict_types=1);
-
-use Hyperf\Snowflake\MetaGenerator\RedisMilliSecondMetaGenerator;
-use Hyperf\Snowflake\MetaGenerator\RedisSecondMetaGenerator;
-use Hyperf\Snowflake\MetaGeneratorInterface;
-
-return [
-    'begin_second' => MetaGeneratorInterface::DEFAULT_BEGIN_SECOND,
-    RedisMilliSecondMetaGenerator::class => [
-        // Redis Pool
-        'pool' => 'default',
-        // 用于计算 WorkerId 的 Key 键
-        'key' => RedisMilliSecondMetaGenerator::DEFAULT_REDIS_KEY
-    ],
-    RedisSecondMetaGenerator::class => [
-        // Redis Pool
-        'pool' => 'default',
-        // 用于计算 WorkerId 的 Key 键
-        'key' => RedisMilliSecondMetaGenerator::DEFAULT_REDIS_KEY
-    ],
-];

+ 0 - 16
config/autoload/translation.php

@@ -1,16 +0,0 @@
-<?php
-
-declare(strict_types=1);
-/**
- * This file is part of Hyperf.
- *
- * @link     https://www.hyperf.io
- * @document https://hyperf.wiki
- * @contact  group@hyperf.io
- * @license  https://github.com/hyperf/hyperf/blob/master/LICENSE
- */
-return [
-    'locale' => 'zh_CN',
-    'fallback_locale' => 'en',
-    'path' => BASE_PATH . '/storage/languages',
-];

+ 0 - 13
config/autoload/validate.php

@@ -1,13 +0,0 @@
-<?php
-return [
-    /**
-     * --------------------------------------------------------------------------------
-     * 自定义数据提供者.
-     * 如果你想自己向验证器提供数据,那么可以尝试修改这个选项
-     * 指定类名,如果不存在则会抛出\RuntimeException异常
-     * 请让你的自定义数据提供者实现\DeathSatan\Hyperf\Validate\Contract\CustomHandle契约.
-     * 只有这样它才不会抛出异常.
-     * --------------------------------------------------------------------------------
-     */
-    'customHandle'=>\DeathSatan\Hyperf\Validate\Driver\RequestHandle::class,
-];

+ 0 - 29
config/autoload/view.php

@@ -1,29 +0,0 @@
-<?php
-
-declare(strict_types=1);
-
-return [
-    'engine' => \Hyperf\ViewEngine\HyperfViewEngine::class,
-    'mode' => \Hyperf\View\Mode::TASK,
-    'config' => [
-        'view_path' => BASE_PATH . '/storage/view/',
-        'cache_path' => BASE_PATH . '/runtime/view/',
-    ],
-    'components' => [
-        'smarty' => [
-            'class' => \App\View\Engine\SmartyEngine::class,
-            'constructor' => [
-                'options' => [
-                    'left_delimiter' => '{{',
-                    'right_delimiter' => '}}',
-                    'compile_dir' => BASE_PATH . '/runtime/smarty/compile/',
-                    'cache_dir' => BASE_PATH . '/runtime/smarty/cache/',
-                    'template_dir' => BASE_PATH . '/storage/view/',
-                ],
-            ],
-        ],
-    ],
-    'composers' => [
-        \App\View\Composers\GlobalComposer::class,
-    ],
-];

+ 10 - 0
storage/view/index.blade.php

@@ -0,0 +1,10 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <title>Hyperf</title>
+</head>
+<body>
+Hello, {{ $name }}. You are using blade template now.
+</body>
+</html>

+ 22 - 9
storage/view/index.tpl

@@ -1,16 +1,29 @@
 <!DOCTYPE html>
-<html>
+<html lang="zh-CN">
 <head>
-    <title>{{$page_title}} - {{$app_name}}</title>
+    <meta charset="UTF-8">
+    <meta name="viewport" content="width=device-width, initial-scale=1.0">
+    <title>{{$title}}</title>
+    <style>
+        body { font-family: 'Microsoft YaHei', sans-serif; max-width: 800px; margin: 0 auto; padding: 20px; }
+        h1 { color: #1890ff; border-bottom: 1px solid #eee; padding-bottom: 10px; }
+        ul { list-style: none; padding: 0; }
+        li { padding: 8px 15px; margin: 5px 0; background: #f7f7f7; border-radius: 4px; }
+        footer { margin-top: 30px; color: #888; font-size: 0.9em; }
+    </style>
 </head>
 <body>
-<h1>欢迎, {{$user.name}}</h1>
+    <h1>{{$title}}</h1>
 
-<div class="info">
-    <p>当前年份: {{$current_year}}</p>
-    <p>版本号: {{$version}}</p>
-    <p>请求处理时间: {{$request_time|number_format:4}}秒</p>
-    <p>客户端IP: {{$request->getAttribute('client_ip')}}</p>
-</div>
+    <h2>主要特性:</h2>
+    <ul>
+        {{foreach $features as $feature}
+            <li>{{$feature}}</li>
+        {{/foreach}}
+    </ul>
+
+    <footer>
+        &copy; {{$current_year}} Hyperf 项目 - 使用Smarty模板引擎渲染
+    </footer>
 </body>
 </html>