66
77use InvalidArgumentException ;
88use Psr \SimpleCache \CacheInterface ;
9+ use SessionHandlerInterface ;
910
1011class Factory
1112{
@@ -17,71 +18,131 @@ public function configFromArray(array $settings): Config
1718 $ config = new Config ();
1819
1920 if (isset ($ settings ['save_path ' ])) {
21+ if (!is_string ($ settings ['save_path ' ])) {
22+ throw new InvalidArgumentException ('save_path must be a string ' );
23+ }
2024 $ config ->setSavePath ($ settings ['save_path ' ]);
2125 }
2226
2327 if (isset ($ settings ['save_handler ' ])) {
28+ if (! ($ settings ['save_handler ' ] instanceof SessionHandlerInterface)) {
29+ throw new InvalidArgumentException ('save_handler must implement SessionHandlerInterface ' );
30+ }
2431 $ config ->setSaveHandler ($ settings ['save_handler ' ]);
2532 }
2633
2734 if (isset ($ settings ['serialize_handler ' ])) {
35+ if (!is_string ($ settings ['serialize_handler ' ]) && !is_null ($ settings ['serialize_handler ' ])) {
36+ throw new InvalidArgumentException ('serialize_handler must be a string or null ' );
37+ }
2838 $ config ->setSerializeHandler (
2939 Serializers \Factory::auto ($ settings ['serialize_handler ' ])
3040 );
3141 }
3242
3343 if (isset ($ settings ['name ' ])) {
44+ if (!is_string ($ settings ['name ' ])) {
45+ throw new InvalidArgumentException ('name must be a string ' );
46+ }
3447 $ config ->setName ($ settings ['name ' ]);
3548 }
3649
3750 if (isset ($ settings ['cookie_lifetime ' ])) {
38- $ config ->setCookieLifetime ((int ) $ settings ['cookie_lifetime ' ]);
51+ if (!is_int ($ settings ['cookie_lifetime ' ])) {
52+ throw new InvalidArgumentException ('cookie_lifetime must be an integer ' );
53+ }
54+ $ config ->setCookieLifetime ($ settings ['cookie_lifetime ' ]);
3955 }
56+
4057 if (isset ($ settings ['cookie_path ' ])) {
58+ if (!is_string ($ settings ['cookie_path ' ])) {
59+ throw new InvalidArgumentException ('cookie_path must be a string ' );
60+ }
4161 $ config ->setCookiePath ($ settings ['cookie_path ' ]);
4262 }
63+
4364 if (isset ($ settings ['cookie_domain ' ])) {
65+ if (!is_string ($ settings ['cookie_domain ' ])) {
66+ throw new InvalidArgumentException ('cookie_domain must be a string ' );
67+ }
4468 $ config ->setCookieDomain ($ settings ['cookie_domain ' ]);
4569 }
70+
4671 if (isset ($ settings ['cookie_secure ' ])) {
47- $ config ->setCookieSecure ((bool ) $ settings ['cookie_secure ' ]);
72+ if (!is_bool ($ settings ['cookie_secure ' ])) {
73+ throw new InvalidArgumentException ('cookie_secure must be a boolean ' );
74+ }
75+ $ config ->setCookieSecure ($ settings ['cookie_secure ' ]);
4876 }
77+
4978 if (isset ($ settings ['cookie_httponly ' ])) {
50- $ config ->setCookieHttpOnly ((bool ) $ settings ['cookie_httponly ' ]);
79+ if (!is_bool ($ settings ['cookie_httponly ' ])) {
80+ throw new InvalidArgumentException ('cookie_httponly must be a boolean ' );
81+ }
82+ $ config ->setCookieHttpOnly ($ settings ['cookie_httponly ' ]);
5183 }
84+
5285 if (isset ($ settings ['cookie_samesite ' ])) {
86+ if (!is_string ($ settings ['cookie_samesite ' ])) {
87+ throw new InvalidArgumentException ('cookie_samesite must be a string ' );
88+ }
5389 $ config ->setCookieSameSite ($ settings ['cookie_samesite ' ]);
5490 }
5591
5692 if (isset ($ settings ['cache_limiter ' ])) {
93+ if (!is_string ($ settings ['cache_limiter ' ])) {
94+ throw new InvalidArgumentException ('cache_limiter must be a string ' );
95+ }
5796 $ config ->setCacheLimiter ($ settings ['cache_limiter ' ]);
5897 }
98+
5999 if (isset ($ settings ['cache_expire ' ])) {
60- $ config ->setCacheExpire ((int ) $ settings ['cache_expire ' ]);
100+ if (!is_int ($ settings ['cache_expire ' ])) {
101+ throw new InvalidArgumentException ('cache_expire must be an integer ' );
102+ }
103+ $ config ->setCacheExpire ($ settings ['cache_expire ' ]);
61104 }
62105
63106 if (isset ($ settings ['gc_probability ' ])) {
64- $ config ->setGcProbability ((int ) $ settings ['gc_probability ' ]);
107+ if (!is_int ($ settings ['gc_probability ' ])) {
108+ throw new InvalidArgumentException ('gc_probability must be an integer ' );
109+ }
110+ $ config ->setGcProbability ($ settings ['gc_probability ' ]);
65111 }
66112
67113 if (isset ($ settings ['gc_divisor ' ])) {
68- $ config ->setGcDivisor ((int ) $ settings ['gc_divisor ' ]);
114+ if (!is_int ($ settings ['gc_divisor ' ])) {
115+ throw new InvalidArgumentException ('gc_divisor must be an integer ' );
116+ }
117+ $ config ->setGcDivisor ($ settings ['gc_divisor ' ]);
69118 }
70119
71120 if (isset ($ settings ['gc_maxlifetime ' ])) {
72- $ config ->setGcMaxLifetime ((int ) $ settings ['gc_maxlifetime ' ]);
121+ if (!is_int ($ settings ['gc_maxlifetime ' ])) {
122+ throw new InvalidArgumentException ('gc_maxlifetime must be an integer ' );
123+ }
124+ $ config ->setGcMaxLifetime ($ settings ['gc_maxlifetime ' ]);
73125 }
74126
75127 if (isset ($ settings ['sid_length ' ])) {
76- $ config ->setSidLength ((int ) $ settings ['sid_length ' ]);
128+ if (!is_int ($ settings ['sid_length ' ])) {
129+ throw new InvalidArgumentException ('sid_length must be an integer ' );
130+ }
131+ $ config ->setSidLength ($ settings ['sid_length ' ]);
77132 }
78133
79134 if (isset ($ settings ['sid_bits_per_character ' ])) {
80- $ config ->setSidBitsPerCharacter ((int ) $ settings ['sid_bits_per_character ' ]);
135+ if (!is_int ($ settings ['sid_bits_per_character ' ])) {
136+ throw new InvalidArgumentException ('sid_bits_per_character must be an integer ' );
137+ }
138+ $ config ->setSidBitsPerCharacter ($ settings ['sid_bits_per_character ' ]);
81139 }
82140
83141 if (isset ($ settings ['lazy_write ' ])) {
84- $ config ->setLazyWrite ((bool ) $ settings ['lazy_write ' ]);
142+ if (!is_bool ($ settings ['lazy_write ' ])) {
143+ throw new InvalidArgumentException ('lazy_write must be a boolean ' );
144+ }
145+ $ config ->setLazyWrite ($ settings ['lazy_write ' ]);
85146 }
86147
87148 return $ config ;
0 commit comments