2 ms·
I like the idea of that for command line, its a wicked project. Seems a bit painful for web use though - I moved away from mapping routes to controllers automat
by antihero 15y ago
I like the idea of that for command line, its a wicked project. Seems a bit painful for web use though - I moved away from mapping routes to controllers automatically in favour of specifying them manually, I feel that it gives great control and leads to less magic. Not knocking your project, though! Good stuff
- dools 15y agoActually 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.