I have situation where i want a config entry which forces the use of https in site. When someone tries to access the site through http he will be redirected to the same page, but using https.
I want to do it PHP side for better accessibility, no .htaccess this time, which would be easy.
Appended my code at app/bootstrap.php then came across the issue that \Uri::current() always returns the base uri. By inspecting the core files found out that the issue might be related to the code not being executed within controllers, after Response class instance being forged.
So my question is is there a global before method or some other kind of middleware i can place my code in?
It depends a bit on where and how you want to do it.
You could do it in your index.php, if you want to check $_SERVER directly, and use that for redirects. If you want to use Fuel, you can do it in your app bootstrap, after the call to Fuel::init().
I'm currently doing it after Fuel::init(), but the Uri::current() still returns the base uri :/
I want to do it the fuelphp-way to make the redirects user happy, as the \Uri::current() also will add parameters. I want the user to use to make the same request to the server just with HTTPS.
The Uri class isn't of much help here, since that uses the active request to determine the current uri, and at that point there is no request yet.
The only way to use the Uri class is to use a base controller (a class all your controllers extend), and use the before() in that base controller.
I would however not do that, it requires the entire framework to be bootstrapped for a redirect, wasting CPU en memory that could be used for legitimate requests.