From faf74039b6035b00a369255691f6ce0218f71732 Mon Sep 17 00:00:00 2001 From: ping-yee <611077101@mail.nknu.edu.tw> Date: Mon, 14 Nov 2022 15:24:52 +0800 Subject: [PATCH 1/4] refactor: repalce time() into Time class in Debug class. --- system/Debug/Toolbar.php | 3 ++- system/Debug/Toolbar/Collectors/Database.php | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/system/Debug/Toolbar.php b/system/Debug/Toolbar.php index 5e70dbc437ff..7824ddedec17 100644 --- a/system/Debug/Toolbar.php +++ b/system/Debug/Toolbar.php @@ -12,6 +12,7 @@ namespace CodeIgniter\Debug; use CodeIgniter\CodeIgniter; +use CodeIgniter\I18n\Time; use CodeIgniter\Debug\Toolbar\Collectors\BaseCollector; use CodeIgniter\Debug\Toolbar\Collectors\Config; use CodeIgniter\Debug\Toolbar\Collectors\History; @@ -380,7 +381,7 @@ public function prepare(?RequestInterface $request = null, ?ResponseInterface $r helper('filesystem'); // Updated to microtime() so we can get history - $time = sprintf('%.6f', microtime(true)); + $time = sprintf('%.6f', Time::now()->format('u')); if (! is_dir(WRITEPATH . 'debugbar')) { mkdir(WRITEPATH . 'debugbar', 0777); diff --git a/system/Debug/Toolbar/Collectors/Database.php b/system/Debug/Toolbar/Collectors/Database.php index 6a845ae51bf3..81770e09e7d4 100644 --- a/system/Debug/Toolbar/Collectors/Database.php +++ b/system/Debug/Toolbar/Collectors/Database.php @@ -12,6 +12,7 @@ namespace CodeIgniter\Debug\Toolbar\Collectors; use CodeIgniter\Database\Query; +use CodeIgniter\I18n\Time; /** * Collector for the Database tab of the Debug Toolbar. @@ -184,7 +185,7 @@ public function display(): array 'sql' => $query['query']->debugToolbarDisplay(), 'trace' => $query['trace'], 'trace-file' => $firstNonSystemLine, - 'qid' => md5($query['query'] . microtime()), + 'qid' => md5($query['query'] . Time::now()->format('u')), ]; }, static::$queries); From 2fcabc4888778f4e69253cd09c741b77ce7dc793 Mon Sep 17 00:00:00 2001 From: ping-yee <611077101@mail.nknu.edu.tw> Date: Mon, 14 Nov 2022 16:32:37 +0800 Subject: [PATCH 2/4] cs-fix in Toolbar. replace time() in Cookie class. --- system/Cookie/Cookie.php | 9 +++++---- system/Debug/Toolbar.php | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/system/Cookie/Cookie.php b/system/Cookie/Cookie.php index b0b49a0a0b7b..9362994329fd 100644 --- a/system/Cookie/Cookie.php +++ b/system/Cookie/Cookie.php @@ -13,6 +13,7 @@ use ArrayAccess; use CodeIgniter\Cookie\Exceptions\CookieException; +use CodeIgniter\I18n\Time; use Config\Cookie as CookieConfig; use DateTimeInterface; use InvalidArgumentException; @@ -206,7 +207,7 @@ final public function __construct(string $name, string $value = '', array $optio // If both `Expires` and `Max-Age` are set, `Max-Age` has precedence. if (isset($options['max-age']) && is_numeric($options['max-age'])) { - $options['expires'] = time() + (int) $options['max-age']; + $options['expires'] = Time::now()->getTimestamp() + (int) $options['max-age']; unset($options['max-age']); } @@ -314,7 +315,7 @@ public function getExpiresString(): string */ public function isExpired(): bool { - return $this->expires === 0 || $this->expires < time(); + return $this->expires === 0 || $this->expires < Time::now()->getTimestamp(); } /** @@ -322,7 +323,7 @@ public function isExpired(): bool */ public function getMaxAge(): int { - $maxAge = $this->expires - time(); + $maxAge = $this->expires - Time::now()->getTimestamp(); return $maxAge >= 0 ? $maxAge : 0; } @@ -466,7 +467,7 @@ public function withNeverExpiring() { $cookie = clone $this; - $cookie->expires = time() + 5 * YEAR; + $cookie->expires = Time::now()->getTimestamp() + 5 * YEAR; return $cookie; } diff --git a/system/Debug/Toolbar.php b/system/Debug/Toolbar.php index 7824ddedec17..9d1182dbb8b7 100644 --- a/system/Debug/Toolbar.php +++ b/system/Debug/Toolbar.php @@ -12,7 +12,6 @@ namespace CodeIgniter\Debug; use CodeIgniter\CodeIgniter; -use CodeIgniter\I18n\Time; use CodeIgniter\Debug\Toolbar\Collectors\BaseCollector; use CodeIgniter\Debug\Toolbar\Collectors\Config; use CodeIgniter\Debug\Toolbar\Collectors\History; @@ -23,6 +22,7 @@ use CodeIgniter\HTTP\RequestInterface; use CodeIgniter\HTTP\Response; use CodeIgniter\HTTP\ResponseInterface; +use CodeIgniter\I18n\Time; use Config\Services; use Config\Toolbar as ToolbarConfig; use Kint\Kint; From 63f238942701bda10190318fe16cb692f3a4d836 Mon Sep 17 00:00:00 2001 From: ping-yee <611077101@mail.nknu.edu.tw> Date: Mon, 14 Nov 2022 16:54:30 +0800 Subject: [PATCH 3/4] add item cookie in deptrac --- deptrac.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/deptrac.yaml b/deptrac.yaml index 3643d19f4118..594f0bba4605 100644 --- a/deptrac.yaml +++ b/deptrac.yaml @@ -158,6 +158,8 @@ parameters: Controller: - HTTP - Validation + Cookie: + - I18n Database: - Entity - Events From 90a8860ef1694dced955e7d78d746e830205ef9f Mon Sep 17 00:00:00 2001 From: ping-yee <611077101@mail.nknu.edu.tw> Date: Tue, 15 Nov 2022 21:11:51 +0800 Subject: [PATCH 4/4] add the format. --- system/Debug/Toolbar.php | 2 +- system/Debug/Toolbar/Collectors/Database.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/system/Debug/Toolbar.php b/system/Debug/Toolbar.php index 9d1182dbb8b7..b5bdcb9c38aa 100644 --- a/system/Debug/Toolbar.php +++ b/system/Debug/Toolbar.php @@ -381,7 +381,7 @@ public function prepare(?RequestInterface $request = null, ?ResponseInterface $r helper('filesystem'); // Updated to microtime() so we can get history - $time = sprintf('%.6f', Time::now()->format('u')); + $time = sprintf('%.6f', Time::now()->format('U.u')); if (! is_dir(WRITEPATH . 'debugbar')) { mkdir(WRITEPATH . 'debugbar', 0777); diff --git a/system/Debug/Toolbar/Collectors/Database.php b/system/Debug/Toolbar/Collectors/Database.php index 81770e09e7d4..2991840c8de1 100644 --- a/system/Debug/Toolbar/Collectors/Database.php +++ b/system/Debug/Toolbar/Collectors/Database.php @@ -185,7 +185,7 @@ public function display(): array 'sql' => $query['query']->debugToolbarDisplay(), 'trace' => $query['trace'], 'trace-file' => $firstNonSystemLine, - 'qid' => md5($query['query'] . Time::now()->format('u')), + 'qid' => md5($query['query'] . Time::now()->format('0.u00 U')), ]; }, static::$queries);