Skip to content

Instantly share code, notes, and snippets.

@alixaxel
Last active December 12, 2015 00:28
Show Gist options
  • Save alixaxel/4683868 to your computer and use it in GitHub Desktop.
Save alixaxel/4683868 to your computer and use it in GitHub Desktop.
<?php
public static function Highway($path, $throttle = null)
{
if ((count($segments = self::Segment()) > 0) && (preg_match('~/$~', $path = ph()->Disk->Path($path)) > 0))
{
$class = null;
while ((is_null($segment = array_shift($segments)) !== true) && (is_dir($path . $class . $segment . '/') === true))
{
$class .= $segment . '/';
}
if (is_file(($class = sprintf('%s%s_%s', $path, $class, $segment)) . '.php') === true)
{
if (is_null($method = array_shift($segments)) === true)
{
$method = self::Value($_SERVER, 'REQUEST_METHOD', 'GET');
}
if (is_callable(array(self::Object($class), $method = sprintf('_%s', strtolower($method)))) === true)
{
if ($throttle > 0)
{
usleep(intval(floatval($throttle) * 1000000));
}
exit(call_user_func_array(array(self::Object($class), $method), $segments));
}
}
throw new Exception('/' . implode('/', self::Segment()), 404);
}
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment