ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
CMS参考了Laravel的设计思想,使用了一个全局App容器(application/common/App.php)。 通过定义Provider,然后在App里注册,即可全局使用。 **登录存储** * 定义 ~~~ $pimple['login'] = function ($pimple) { $driver = Config::get('login_driver') ? Config::get('login_driver') : LoginFactory::TYPE_SESSION; return LoginFactory::make($driver); }; ~~~ * 使用 ~~~ use app\common\App; $login = App::getSingleton()->login; ~~~ **文件存储** * 定义 ~~~ $pimple['storage'] = function ($pimple) { $driver = Config::get('upload_driver'); $option = Config::get('upload_' . $driver); return StorageFactory::make($driver, $option); }; ~~~ * 使用 ~~~ use app\common\App; $login = App::getSingleton()->storage; ~~~ **上传对象** * 定义 ~~~ $pimple['upload'] = function ($pimple) { $upload = new Upload($pimple['storage']); // 验证文件是否上传 $upload->addHook(Upload::HOOK_UPLOAD_CHECK, CheckHook::class); // 文件上传成功的处理 $upload->addHook(Upload::HOOK_UPLOAD_SUCCESS, SuccessHook::class); return $upload; }; ~~~ * 使用 ~~~ use app\common\App; $login = App::getSingleton()->upload; ~~~