diff --git a/app/Config/App.php b/app/Config/App.php index 0c19c1c54d..002f6abc97 100644 --- a/app/Config/App.php +++ b/app/Config/App.php @@ -46,6 +46,7 @@ 'Str' => '\Support\Str', // The Support Facades + 'App' => '\Support\Facades\App', 'Auth' => '\Support\Facades\Auth', 'Cookie' => '\Support\Facades\Cookie', 'Crypt' => '\Support\Facades\Crypt', diff --git a/app/Modules/Users/Views/Admin/Roles/Index.php b/app/Modules/Users/Views/Admin/Roles/Index.php index e771e45afc..b27c8fbc7b 100644 --- a/app/Modules/Users/Views/Admin/Roles/Index.php +++ b/app/Modules/Users/Views/Admin/Roles/Index.php @@ -43,10 +43,10 @@ echo " " .$role->id ." - " .$role->name ." - " .$role->slug ." - " .$role->description ." - " .$role->users->count() ." + " .$role->name ." + " .$role->slug ." + " .$role->description ." + " .$role->users->count() ."
id). "' title='". __d('users', 'Show the Details') ."' role='button'> diff --git a/system/Core/Controller.php b/system/Core/Controller.php index f7ca689664..0db0247492 100644 --- a/system/Core/Controller.php +++ b/system/Core/Controller.php @@ -16,9 +16,9 @@ use Symfony\Component\HttpFoundation\Response as SymfonyResponse; +use App; use Event; use Response; -use Session; /** @@ -133,7 +133,7 @@ public function execute($method, $params = array()) // The Method returned a Response instance; send it and stop the processing. if ($result instanceof SymfonyResponse) { // Finish the Session and send the Response. - Session::finish($result); + App::finish($result); return true; } @@ -181,7 +181,7 @@ protected function createResponse($result) $response = Response::make($content, 200, $headers); // Finish the Session and send the Response. - Session::finish($response); + App::finish($response); return true; } else if (! $result instanceof BaseView) { @@ -199,7 +199,7 @@ protected function createResponse($result) $response = Response::make($result); // Finish the Session and send the Response. - Session::finish($response); + App::finish($response); return true; } diff --git a/system/Helpers/Url.php b/system/Helpers/Url.php index 9e92a14c19..f6edeb2804 100644 --- a/system/Helpers/Url.php +++ b/system/Helpers/Url.php @@ -12,7 +12,7 @@ use Helpers\Inflector; use Support\Facades\Redirect; -use Support\Facades\Session as SessionStore; +use Support\Facades\App; /** @@ -36,7 +36,7 @@ public static function redirect($url = null, $fullPath = false, $code = 302) $response = Redirect::to($url, $code); // Finish the Session (and send the Response). - SessionStore::finish($response); + App::finish($response); // Quit the Nova Framework's execution. exit(); diff --git a/system/Routing/BaseRouter.php b/system/Routing/BaseRouter.php index 3a84745916..adf5c4300e 100644 --- a/system/Routing/BaseRouter.php +++ b/system/Routing/BaseRouter.php @@ -16,9 +16,9 @@ use Symfony\Component\HttpFoundation\Response as SymfonyResponse; use Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesser; +use App; use Console; use Response; -use Session; /** @@ -157,7 +157,7 @@ protected function invokeCallback($callback, $params = array()) if($result instanceof SymfonyResponse) { // Finsih the Session Store. - Session::finish($result); + App::finish($result); // Send the Response. $result->send(); @@ -166,7 +166,7 @@ protected function invokeCallback($callback, $params = array()) $response = Response::make($result); // Finish the Session Store. - Session::finish($response); + App::finish($response); // Send the Response. $response->send(); diff --git a/system/Routing/ClassicRouter.php b/system/Routing/ClassicRouter.php index f74dd0a8c5..caa255c7df 100644 --- a/system/Routing/ClassicRouter.php +++ b/system/Routing/ClassicRouter.php @@ -15,9 +15,9 @@ use Routing\BaseRouter; use Routing\Route; +use App; use Response; use Request; -use Session; /** @@ -127,7 +127,7 @@ public function dispatch() $response = Response::error(404, $data); // Finish the Session and send the Response. - Session::finish($response); + App::finish($response); return false; } diff --git a/system/Routing/Router.php b/system/Routing/Router.php index 5978aeab4a..ddf4cce33b 100644 --- a/system/Routing/Router.php +++ b/system/Routing/Router.php @@ -16,9 +16,9 @@ use Symfony\Component\HttpFoundation\Response as SymfonyResponse; +use App; use Response; use Request; -use Session; /** @@ -256,7 +256,7 @@ public function dispatch() if($result instanceof SymfonyResponse) { // Finish the Session and send the Response. - Session::finish($result); + App::finish($result); return true; } @@ -279,7 +279,7 @@ public function dispatch() $response = Response::error(404, $data); // Finish the Session and send the Response. - Session::finish($response); + App::finish($response); return false; } diff --git a/system/Support/Facades/App.php b/system/Support/Facades/App.php new file mode 100644 index 0000000000..ef066416ff --- /dev/null +++ b/system/Support/Facades/App.php @@ -0,0 +1,192 @@ +getId(), + $config['lifetime'], + $config['path'], + $config['domain'], + $config['secure'], + false + ); + + Cookie::queue($cookie); + + // Save the Session Store data. + $session->save(); + + // Collect the garbage for the Session Store instance. + static::collectGarbage($session, $config); + + // Add all Request and queued Cookies. + static::processCookies($response, $config); + + // Finally, minify the Response's Content. + static::processContent($response); + + // Prepare the Response instance for sending. + $response->prepare($request); + + // Send the Response. + $response->send(); + } + + /** + * Minify the Response instance Content. + * + * @param \Symfony\Component\HttpFoundation\Response $response + * @return void + */ + protected static function processContent(SymfonyResponse $response) + { + if (! $response instanceof HttpResponse) { + return; + } + + $content = $response->getContent(); + + if(ENVIRONMENT == 'development') { + // Insert the QuickProfiler Widget in the Response's Content. + + $content = str_replace( + '', + QuickProfiler::process(true), + $content + ); + } else if(ENVIRONMENT == 'production') { + // Minify the Response's Content. + + $search = array( + '/\>[^\S ]+/s', // Strip whitespaces after tags, except space. + '/[^\S ]+\', '<', '\\1'); + + $content = preg_replace($search, $replace, $content); + } + + $response->setContent($content); + } + + /** + * Remove the garbage from the session if necessary. + * + * @param \Illuminate\Session\SessionInterface $session + * @return void + */ + protected static function collectGarbage(SessionInterface $session, array $config) + { + $lifeTime = $config['lifetime'] * 60; // The option is in minutes. + + // Here we will see if this request hits the garbage collection lottery by hitting + // the odds needed to perform garbage collection on any given request. If we do + // hit it, we'll call this handler to let it delete all the expired sessions. + if (static::configHitsLottery($config)) { + $session->getHandler()->gc($lifeTime); + } + } + + /** + * Add all the queued Cookies to Response instance and encrypt all Cookies. + * + * @return void + */ + protected static function processCookies(SymfonyResponse $response, array $config) + { + // Insert all queued Cookies on the Response instance. + foreach (Cookie::getQueuedCookies() as $cookie) { + $response->headers->setCookie($cookie); + } + + if($config['encrypt'] == false) { + // The Cookies encryption is disabled. + return; + } + + // Encrypt all Cookies present on the Response instance. + foreach ($response->headers->getCookies() as $key => $cookie) { + if($key == 'PHPSESSID') { + // Leave alone the PHPSESSID. + continue; + } + + // Create a new Cookie with the content encrypted. + $cookie = new SymfonyCookie( + $cookie->getName(), + Crypt::encrypt($cookie->getValue()), + $cookie->getExpiresTime(), + $cookie->getPath(), + $cookie->getDomain(), + $cookie->isSecure(), + $cookie->isHttpOnly() + ); + + $response->headers->setCookie($cookie); + } + } + + /** + * Determine if the configuration odds hit the lottery. + * + * @param array $config + * @return bool + */ + protected static function configHitsLottery(array $config) + { + return (mt_rand(1, $config['lottery'][1]) <= $config['lottery'][0]); + } +} diff --git a/system/Support/Facades/Session.php b/system/Support/Facades/Session.php index 48ae29bff9..2a5b40b943 100644 --- a/system/Support/Facades/Session.php +++ b/system/Support/Facades/Session.php @@ -10,21 +10,11 @@ use Core\Config; use Core\Template; -use Core\BaseView as View; -use Forensics\Profiler as QuickProfiler; -use Http\Response as HttpResponse; use Session\FileSessionHandler; -use Session\SessionInterface; use Session\Store as SessionStore; use Support\Facades\Cookie; -use Support\Facades\Crypt; -use Support\Facades\Request; use Support\MessageBag; -use Symfony\Component\HttpFoundation\Cookie as SymfonyCookie; -use Symfony\Component\HttpFoundation\Response as SymfonyResponse; - - class Session { @@ -115,162 +105,6 @@ public static function init() Cookie::queue($cookie); } - /** - * Finalize the Session Store and send the Response - * - * @param \Symfony\Component\HttpFoundation\Response $response - * @return void - */ - public static function finish(SymfonyResponse $response) - { - // Get the Session Store configuration. - $config = Config::get('session'); - - // Get the Request instance. - $request = Request::instance(); - - // Get the Session Store instance. - $session = static::getSessionStore(); - - // Store the Session ID in a Cookie. - $cookie = Cookie::make( - $config['cookie'], - $session->getId(), - $config['lifetime'], - $config['path'], - $config['domain'], - $config['secure'], - false - ); - - Cookie::queue($cookie); - - // Save the Session Store data. - $session->save(); - - // Collect the garbage for the Session Store instance. - static::collectGarbage($session, $config); - - // Add all Request and queued Cookies. - static::processCookies($response, $config); - - // Finally, minify the Response's Content. - static::processContent($response); - - // Prepare the Response instance for sending. - $response->prepare($request); - - // Send the Response. - $response->send(); - } - - /** - * Minify the Response instance Content. - * - * @param \Symfony\Component\HttpFoundation\Response $response - * @return void - */ - protected static function processContent(SymfonyResponse $response) - { - if (! $response instanceof HttpResponse) { - return; - } - - $content = $response->getContent(); - - if(ENVIRONMENT == 'development') { - // Insert the QuickProfiler Widget in the Response's Content. - - $content = str_replace( - '', - QuickProfiler::process(true), - $content - ); - } else if(ENVIRONMENT == 'production') { - // Minify the Response's Content. - - $search = array( - '/\>[^\S ]+/s', // Strip whitespaces after tags, except space. - '/[^\S ]+\', '<', '\\1'); - - $content = preg_replace($search, $replace, $content); - } - - $response->setContent($content); - } - - /** - * Remove the garbage from the session if necessary. - * - * @param \Illuminate\Session\SessionInterface $session - * @return void - */ - protected static function collectGarbage(SessionInterface $session, array $config) - { - $lifeTime = $config['lifetime'] * 60; // The option is in minutes. - - // Here we will see if this request hits the garbage collection lottery by hitting - // the odds needed to perform garbage collection on any given request. If we do - // hit it, we'll call this handler to let it delete all the expired sessions. - if (static::configHitsLottery($config)) { - $session->getHandler()->gc($lifeTime); - } - } - - /** - * Add all the queued Cookies to Response instance and encrypt all Cookies. - * - * @return void - */ - protected static function processCookies(SymfonyResponse $response, array $config) - { - // Insert all queued Cookies on the Response instance. - foreach (Cookie::getQueuedCookies() as $cookie) { - $response->headers->setCookie($cookie); - } - - if($config['encrypt'] == false) { - // The Cookies encryption is disabled. - return; - } - - // Encrypt all Cookies present on the Response instance. - foreach ($response->headers->getCookies() as $key => $cookie) { - if($key == 'PHPSESSID') { - // Leave alone the PHPSESSID. - continue; - } - - // Create a new Cookie with the content encrypted. - $cookie = new SymfonyCookie( - $cookie->getName(), - Crypt::encrypt($cookie->getValue()), - $cookie->getExpiresTime(), - $cookie->getPath(), - $cookie->getDomain(), - $cookie->isSecure(), - $cookie->isHttpOnly() - ); - - $response->headers->setCookie($cookie); - } - } - - /** - * Determine if the configuration odds hit the lottery. - * - * @param array $config - * @return bool - */ - protected static function configHitsLottery(array $config) - { - return (mt_rand(1, $config['lottery'][1]) <= $config['lottery'][0]); - } - /** * Return a Session Store instance * @@ -413,7 +247,7 @@ public static function __callStatic($method, $params) // Get the Session Store instance. $instance = static::getSessionStore(); - // Call the non-static method from the Request instance. + // Call the non-static method from the Session Store instance. return call_user_func_array(array($instance, $method), $params); } }