12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- <?php
-
- class glue {
-
- static function stick ($urls) {
- $method = strtoupper($_SERVER['REQUEST_METHOD']);
- $path = $_SERVER['REQUEST_URI'];
- $found = false;
- krsort($urls);
- foreach ($urls as $regex => $class) {
- $regex = str_replace('/', '\/', $regex);
- $regex = '^' . $regex . '\/?$';
- if (preg_match("/$regex/i", $path, $matches)) {
- $found = true;
- if (class_exists($class)) {
- $obj = new $class;
- if (method_exists($obj, $method)) {
- $obj->$method($matches);
- } else {
- throw new BadMethodCallException("Method, $method, not supported.");
- }
- } else {
- throw new Exception("Class, $class, not found.");
- }
- break;
- }
- }
- if (!$found) {
- throw new Exception("URL, $path, not found.");
- }
- }
- }
|