From 77c734532367f8a34e473dbce5d513c8076716d4 Mon Sep 17 00:00:00 2001 From: Rhilip Date: Thu, 23 Jan 2020 21:50:56 +0800 Subject: [PATCH] fix(User): Fix all user class info become cur_user 1. Fix all user class info become cur_user 2. Fix `PHP Notice: Array to string conversion in /data/wwwroot/ridp.top/application/Controllers/TrackerController.php on line 166` 3. Fix app()->request->server->get('query_string') can't get $_SERVER['QUERY_STRING'], use app()->request->getQueryString() instead. 4. Use magic function __toString() to get string format info of `app()->request->headers` --- CHANGELOG.md | 1 + application/Controllers/TrackerController.php | 10 ++++------ application/Entity/User/AbstractUser.php | 6 ++---- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3f0ae40..425ee03 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ - **phpstorm:** Add `.phpstorm.meat.php` for config() function (407bb66) ### Feat +- **Requests:** Make Request Component extends from `Symfony\Component\HttpFoundation\Request` (9cd715b) - **Torrent:** Per-add torrent edit (f06b342) - **i18n:** Use symfony/translation and JSON format for locale (02cc251) - **layout:** Add anti-robots html meta tag (9c21e73) diff --git a/application/Controllers/TrackerController.php b/application/Controllers/TrackerController.php index 9b5b5a7..42251e6 100644 --- a/application/Controllers/TrackerController.php +++ b/application/Controllers/TrackerController.php @@ -161,10 +161,8 @@ public function actionIndex() protected function logException(\Exception $exception, $userInfo = null, $torrentInfo = null) { - $req_info = app()->request->server->get('query_string') . "\n\n"; - foreach (app()->request->headers->all() as $key => $value) { - $req_info .= "$key : $value \n"; - } + $req_info = app()->request->getQueryString() . "\n\n"; + $req_info .= (string) app()->request->headers; app()->pdo->createCommand('INSERT INTO `agent_deny_log`(`tid`, `uid`, `user_agent`, `peer_id`, `req_info`,`create_at`, `msg`) VALUES (:tid,:uid,:ua,:peer_id,:req_info,CURRENT_TIMESTAMP,:msg) @@ -472,7 +470,7 @@ private function getTorrentInfoByHash($hash, bool $scrape = false) */ private function checkScrapeFields(&$info_hash_array) { - preg_match_all('/info_hash=([^&]*)/i', urldecode(app()->request->server->get('query_string')), $info_hash_match); + preg_match_all('/info_hash=([^&]*)/i', urldecode(app()->request->getQueryString()), $info_hash_match); $info_hash_array = $info_hash_match[1]; if (count($info_hash_array) < 1) { @@ -701,7 +699,7 @@ private function getTorrentInfo($queries, $userInfo, &$torrentInfo) */ private function lockAnnounceDuration() { - $identity = md5(urldecode(app()->request->server->get('query_string'))); + $identity = md5(urldecode(app()->request->getQueryString())); if (false == $check = app()->redis->zScore(Constant::trackerAnnounceLockZset, $identity)) { // this identity is not lock app()->redis->zAdd(Constant::trackerAnnounceLockZset, time() + 60, $identity); } diff --git a/application/Entity/User/AbstractUser.php b/application/Entity/User/AbstractUser.php index e2cfbc4..d5ce709 100644 --- a/application/Entity/User/AbstractUser.php +++ b/application/Entity/User/AbstractUser.php @@ -31,16 +31,14 @@ class AbstractUser extends BaseObject implements AbstractUserInterface protected function getCacheNameSpace(): string { - if (is_null($this->info_cache_key)) { - $this->info_cache_key = Constant::userContent($this->id); - } - return $this->info_cache_key; } + /** @noinspection PhpMissingParentConstructorInspection */ public function __construct($id = 0) { $this->id = $id; + $this->info_cache_key = Constant::userContent($this->id); $self = app()->redis->hGetAll($this->info_cache_key); if (empty($self) || !isset($self['id'])) { if (app()->redis->zScore(Constant::invalidUserIdZset, $id) === false) {