Created
May 3, 2014 19:57
-
-
Save silvasur/1dddb445c71a6ad29d73 to your computer and use it in GitHub Desktop.
A Workaround for issue #82 of anandkunal/ToroPHP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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); | |
} | |
} |
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
impressive !