@@ -35,6 +35,26 @@ class Session
3535 */
3636 private $ domainName ;
3737
38+ /**
39+ * @var string
40+ */
41+ private $ cookiePath = '/ ' ;
42+
43+ /**
44+ * @var bool
45+ */
46+ private $ cookieHttpOnly = false ;
47+
48+ /**
49+ * @var bool
50+ */
51+ private $ cookieSecure = false ;
52+
53+ /**
54+ * @var string
55+ */
56+ private $ cookieSameSite = '' ;
57+
3858 /**
3959 * @param array $options
4060 */
@@ -127,13 +147,48 @@ public function setDomainName($domainName): Session
127147 return $ this ;
128148 }
129149
150+ public function cookiePath (string $ path )
151+ {
152+ $ this ->cookiePath = $ path ;
153+ return $ this ;
154+ }
155+
156+ public function cookieHttpOnly (bool $ value )
157+ {
158+ $ this ->cookieHttpOnly = $ value ;
159+ return $ this ;
160+ }
161+
162+ public function cookieSecure (bool $ value )
163+ {
164+ $ this ->cookieSecure = $ value ;
165+ return $ this ;
166+ }
167+
168+ public function cookieSameSite (string $ value )
169+ {
170+ $ validValues = ['' , 'None ' , 'Strict ' ];
171+ if (!in_array ($ value , $ validValues )) {
172+ throw new \InvalidArgumentException ('Invalid value for cookieSameSite ' );
173+ }
174+ $ this ->cookieSameSite = $ value ;
175+ return $ this ;
176+ }
177+
130178 /**
131179 * @return Session
132180 * @throws MissingDomainNameException
133181 */
134182 public function start (): Session
135183 {
136- session_set_cookie_params ($ this ->getLifetime (), '/ ' , $ this ->getDomainName ());
184+ session_set_cookie_params ([
185+ 'lifetime ' => $ this ->getLifetime (),
186+ 'path ' => $ this ->cookiePath ,
187+ 'domain ' => $ this ->getDomainName (),
188+ 'secure ' => $ this ->cookieSecure ,
189+ 'httponly ' => $ this ->cookieHttpOnly ,
190+ 'samesite ' => $ this ->cookieSameSite ,
191+ ]);
137192
138193 $ this ->manager = new SessionManager ($ this ->getConfig ());
139194 $ this ->manager
0 commit comments