Skip to content

Instantly share code, notes, and snippets.

@elazar
Created February 15, 2012 02:54
Show Gist options
  • Save elazar/1832757 to your computer and use it in GitHub Desktop.
Save elazar/1832757 to your computer and use it in GitHub Desktop.
Delayed route loading in Slim
<?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();
<?php
return function() {
echo 'Hello world!';
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment