Created
February 15, 2012 02:54
-
-
Save elazar/1832757 to your computer and use it in GitHub Desktop.
Delayed route loading in Slim
This file contains 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 | |
require_once 'Slim/Slim.php'; | |
class Custom_Route extends Slim_Route { | |
public function dispatch() { | |
$this->setCallable(require $this->getCallable()); | |
return parent::dispatch(); | |
} | |
} | |
class Custom_Router extends Slim_Router { | |
public function map( $pattern, $callable ) { | |
$route = new Custom_Route($pattern, $callable); | |
$route->setRouter($this); | |
$this->routes[] = $route; | |
return $route; | |
} | |
} | |
$slim = new Slim; | |
$slim->router(new Custom_Router()); | |
$slim->get('/', 'example_get.php'); | |
$slim->run(); |
This file contains 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 | |
return function() { | |
echo 'Hello world!'; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment