@@ -568,7 +568,7 @@ public function setCookie(
568568 $ httponly = null ,
569569 $ samesite = null ,
570570 ) {
571- $ store = $ this ->initializeCookieStore ();
571+ $ store = $ this ->getCookieStore ();
572572
573573 if ($ name instanceof Cookie) {
574574 $ this ->cookieStore = $ store ->put ($ name );
@@ -613,19 +613,24 @@ public function setCookie(
613613 /**
614614 * Returns the `CookieStore` instance.
615615 *
616+ * Lazily instantiates the `CookieStore` on first call, so that the Cookie and
617+ * CookieStore classes are not loaded on requests that do not use cookies.
618+ *
616619 * @return CookieStore
617620 */
618621 public function getCookieStore ()
619622 {
620- return $ this ->initializeCookieStore ();
623+ $ this ->cookieStore ??= new CookieStore ([]);
624+
625+ return $ this ->cookieStore ;
621626 }
622627
623628 /**
624629 * Checks to see if the Response has a specified cookie or not.
625630 */
626631 public function hasCookie (string $ name , ?string $ value = null , string $ prefix = '' ): bool
627632 {
628- $ store = $ this ->initializeCookieStore ();
633+ $ store = $ this ->getCookieStore ();
629634 $ prefix = $ prefix !== '' ? $ prefix : Cookie::setDefaults ()['prefix ' ]; // to retain BC
630635
631636 return $ store ->has ($ name , $ prefix , $ value );
@@ -641,7 +646,7 @@ public function hasCookie(string $name, ?string $value = null, string $prefix =
641646 */
642647 public function getCookie (?string $ name = null , string $ prefix = '' )
643648 {
644- $ store = $ this ->initializeCookieStore ();
649+ $ store = $ this ->getCookieStore ();
645650
646651 if ((string ) $ name === '' ) {
647652 return $ store ->display ();
@@ -669,7 +674,7 @@ public function deleteCookie(string $name = '', string $domain = '', string $pat
669674 return $ this ;
670675 }
671676
672- $ store = $ this ->initializeCookieStore ();
677+ $ store = $ this ->getCookieStore ();
673678 $ prefix = $ prefix !== '' ? $ prefix : Cookie::setDefaults ()['prefix ' ]; // to retain BC
674679
675680 $ prefixed = $ prefix . $ name ;
@@ -812,21 +817,8 @@ public function download(string $filename = '', $data = '', bool $setMime = fals
812817
813818 public function getCSP (): ContentSecurityPolicy
814819 {
815- return $ this ->CSP ??= service ('csp ' );
816- }
817-
818- /**
819- * Lazily initializes the cookie store and the Cookie class defaults.
820- * Called by every cookie-related method so cookie machinery is only
821- * loaded when the developer actually interacts with cookies.
822- */
823- private function initializeCookieStore (): CookieStore
824- {
825- if ($ this ->cookieStore === null ) {
826- Cookie::setDefaults (config (CookieConfig::class));
827- $ this ->cookieStore = new CookieStore ([]);
828- }
820+ $ this ->CSP ??= service ('csp ' );
829821
830- return $ this ->cookieStore ;
822+ return $ this ->CSP ;
831823 }
832824}
0 commit comments