public static function stick($routes) { if (isset($_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'])) { $method = strtoupper($_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE']); } else { if (isset($_REQUEST['_method'])) { $method = strtoupper($_REQUEST['_method']); } else { $method = strtoupper($_SERVER['REQUEST_METHOD']); } } if (!in_array($method, self::$allowedMethods)) { throw new BadMethodCallException("Method, {$method}, not supported"); exit; } $path = sgContext::getCurrentPath(); $matchedRoute = null; if (sgConfiguration::get('settings.cache_routes')) { $matchedRoute = self::checkRouteCache($path, $method); } if (!$matchedRoute) { foreach ($routes as $name => $route) { $matches = array(); $regex = str_replace('/', '\\/', $route['path']); $regex = '^' . $regex . '\\/?$'; if (preg_match("/{$regex}/i", $path, $matches)) { $route['name'] = $name; $route['matches'] = $matches; $route['path'] = $path; $matchedRoute = $route; self::$cachedRoutes["{$method} {$path}"] = $matchedRoute; break; } } } if (!$matchedRoute) { if (sgConfiguration::get('settings.magic_routing')) { $matchedRoute = array('path' => $path, 'class' => 'sgMagicController', 'method' => $method, 'matches' => array()); self::$cachedRoutes["{$method} {$path}"] = $matchedRoute; } else { $obj = new sgBaseController($matches); print $obj->throwErrorCode('404'); } } if ($matchedRoute) { if (!sgConfiguration::get('settings.magic_routing') && $matchedRoute['class'] == 'sgMagicController') { $obj = new sgBaseController($matchedRoute['matches']); print $obj->throwErrorCode('404'); } else { self::dispatch($matchedRoute, $method, $matchedRoute['matches']); } } self::shutdown(); sgAutoloader::shutdown(); }