Skip to content

Instantly share code, notes, and snippets.

@silvasur
Created May 3, 2014 19:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save silvasur/1dddb445c71a6ad29d73 to your computer and use it in GitHub Desktop.
Save silvasur/1dddb445c71a6ad29d73 to your computer and use it in GitHub Desktop.
A Workaround for issue #82 of anandkunal/ToroPHP
<?php
class ToroWorkaround {
public static function serve($handlers) {
/*
* Toro prefers the $_SERVER["PATH_INFO"] var to get the requested URL.
* If this var is present, everything seems to be correct.
* If it is not, some weird errors occur.
* For example, Toro sometimes can not route to the index route ("/"), when the app is not running from the servers document root.
* By constructing PATH_INFO manually using REQUEST_URI and SCRIPT_NAME, we can work around this problem.
*/
if(!isset($_SERVER["PATH_INFO"])) {
$r = $_SERVER['REQUEST_URI'];
if(strpos($r, '?')) {
$r = strstr($r, '?', true);
}
$request = explode('/', $r);
$script = explode('/', $_SERVER['SCRIPT_NAME']);
for($i = 0; $i < count($script); $i++) {
if($request[$i] !== $script[$i]) {
break;
}
}
$u = array_slice($request, $i);
if($u[count($u)-1] === '') {
$u = array_slice($u, 0, count($u)-1);
}
$_SERVER["PATH_INFO"] = '/'.implode('/', $u);
}
\Toro::serve($handlers);
}
}
@ipranjal
Copy link

impressive !

@ipranjal
Copy link

error: undefined offset -1 while using post method !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment