1818use webfiori \file \exceptions \FileException ;
1919use webfiori \file \File ;
2020use webfiori \framework \autoload \ClassLoader ;
21- use webfiori \framework \cache \Cache ;
2221use webfiori \framework \config \ConfigurationDriver ;
2322use webfiori \framework \config \Controller ;
2423use webfiori \framework \exceptions \InitializationException ;
2524use webfiori \framework \handlers \APICallErrHandler ;
2625use webfiori \framework \handlers \CLIErrHandler ;
2726use webfiori \framework \handlers \HTTPErrHandler ;
2827use webfiori \framework \middleware \AbstractMiddleware ;
28+ use webfiori \framework \middleware \CacheMiddleware ;
2929use webfiori \framework \middleware \MiddlewareManager ;
30+ use webfiori \framework \middleware \StartSessionMiddleware ;
3031use webfiori \framework \router \Router ;
3132use webfiori \framework \router \RouterUri ;
3233use webfiori \framework \scheduler \TasksManager ;
33- use webfiori \framework \session \SessionsManager ;
3434use webfiori \http \Request ;
3535use webfiori \http \Response ;
3636/**
@@ -154,7 +154,6 @@ private function __construct() {
154154 {
155155 register_shutdown_function (function ()
156156 {
157- SessionsManager::validateStorage ();
158157 $ uriObj = Router::getRouteUri ();
159158
160159 if ($ uriObj !== null ) {
@@ -163,14 +162,6 @@ private function __construct() {
163162 }
164163 }
165164 });
166- try {
167- $ sessionsCookiesHeaders = SessionsManager::getCookiesHeaders ();
168-
169- foreach ($ sessionsCookiesHeaders as $ headerVal ) {
170- Response::addHeader ('set-cookie ' , $ headerVal );
171- }
172- } catch (Error $ exc ) {
173- }
174165
175166 $ uriObj = Router::getRouteUri ();
176167
@@ -180,21 +171,11 @@ private function __construct() {
180171 foreach ($ uriObj ->getMiddleware () as $ mw ) {
181172 $ mw ->after (Request::get (), Response::get ());
182173 }
183- App::cacheResponse ($ uriObj ->getUri (true , true ), $ uriObj ->getCacheDuration ());
184174 }
185175 });
186176 //class is now initialized
187177 self ::$ ClassStatus = self ::STATUS_INITIALIZED ;
188178 }
189- public static function cacheResponse (string $ key , int $ duration ) {
190- Cache::get ($ key , function () {
191- return [
192- 'headers ' => Response::getHeaders (),
193- 'http-code ' => Response::getCode (),
194- 'body ' => Response::getBody ()
195- ];
196- }, $ duration );
197- }
198179 /**
199180 * Register CLI commands or background tasks.
200181 *
@@ -317,7 +298,8 @@ public static function handle() {
317298 App::getRunner ()->start ();
318299 } else {
319300 //route user request.
320- SessionsManager::start ('wf-session ' );
301+ MiddlewareManager::register (new StartSessionMiddleware ());
302+ MiddlewareManager::register (new CacheMiddleware ());
321303 Router::route (Request::getRequestedURI ());
322304 Response::send ();
323305 }
@@ -538,7 +520,8 @@ private function checkStandardLibs() {
538520 'webfiori/file ' => 'webfiori \\file \\File ' ,
539521 'webfiori/mailer ' => 'webfiori \\email \\SMTPAccount ' ,
540522 'webfiori/cli ' => 'webfiori \\cli \\CLICommand ' ,
541- 'webfiori/err ' => 'webfiori \\error \\ErrorHandlerException '
523+ 'webfiori/err ' => 'webfiori \\error \\ErrorHandlerException ' ,
524+ 'webfiori/cache ' => 'webfiori \\cache \\Cache '
542525 ];
543526
544527 foreach ($ standardLibsClasses as $ lib => $ class ) {
0 commit comments