4 ms·
Actually it doesn't even do that! It does so little - that r= argument just has to be a class that is autoloadable and implements the Runnable interface. In fa
by dools 15y ago
Actually it doesn't even do that! It does so little - that r= argument just has to be a class that is autoloadable and implements the Runnable interface.
In fact, if you want routes you'd have to build it as a package and in FACT you could just create a class like this:
class RocketHam implements rocketsled\Runnable
{
public function run()
{
$app = new Ham();
$app->config_from_file('settings.php');
$app->route('/pork', function($app) {
return "Delicious pork.";
});
$hello = function($app, $name='world') {
return $app->render('hello.html', array(
'name' => $name
));
};
$app->route('/hello/<string>', $hello);
$app->route('/', $hello);
$app->run();
}
}
then put your ham/ directory in packages with a file rs.config.php:
spl_autoload_register(function($class)
{
if($class == 'Ham')
require_once(dirname(__FILE__).'/ham.php');
}
then use .htaccess or something similar to route all requests to:
index.php?r=RocketHam
EDITS: oops sorry not used to formatting code on here
- antihero 15y agoGotcha, that's kinda cool. I just learned about this http://www.php.net/manual/en/language.oop5.magic.php#object.invoke http://www.php.net/manual/en/language.oop5.magic.php#object.... The __invoke method means I can use my apps AS closures which is totally sweet.