by dools · 14y ago · 0 comments
It's interesting to see the growing trend in this direction for PHP.
I wrote one a little while back[1] that does even less than this :) The only goal being to provide a simple way to execute classes from the web or command line with a default autoloading implementation and a way to inject new ones[2]
Personally a lot of my current direction in PHP comes from watching what's happening the node.js community - I like the way that there are a lot of small-ish packages/modules that are pretty independent.
I've written a couple of packages for RocketSled already which you can see on my github page if you're interested.
[1] https://github.com/iaindooley/RocketSled
[2] There are some obvious improvements that could be made to the current implementation which always parses the package tree ie. caching
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
The __invoke method means I can use my apps AS closures which is totally sweet.