dev-master
9999999-dev https://github.com/radiosilence/HamPHP Microframework for use with whatever you like.
BSD-2-Clause
The Requires
- php >=5.3
microframework router
Wallogit.com
2017 © Pedro Peláez
PHP Microframework for use with whatever you like.
Now includes tests!, (*1)
PHP Microframework for use with whatever you like. Basically just a fast router with nice syntax, and a cache singleton. Will add more things as I go, like perhaps an extension system, autoloader and some other stuff to make developing in PHP less irritating than it currently is., (*2)
Routes are converted to regex and cached so this process does not need to happen every request. Furthermore, the resolved route for a given URI is also cached so on most requests thare is no regex matching involved., (*3)
There is also now the ability to mount apps on routes within apps, so one could make an administrator app, then mount it on the main app at /admin., (*4)
PHP presents an interesting challenge because due to it's architecture, everything has to be re-done each request, which is why I'm leveraging caching with tiny TTLs to share the results of operations like route resolution between requests., (*5)
Note: PHP already has many of the features that many microframeworks have, such as session handling, cookies, and templating. An aim of this project is to encourage the use of native functionality where possible or where it is good, but make some parts nicer or extend upon them to bring it up to scratch with the way I like things., (*6)
Note: For maximum speed gains, use the XCache extension because that supports caching of closures, unlike APC., (*7)
Inspired entirely by Flask., (*8)
require '../ham/ham.php';
$app = new Ham('example');
$app->route('/', function($app) {
return 'Hello, world!';
});
$app->run();
require '../ham/ham.php';
$app = new Ham('example');
$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();
require '../ham/ham.php';
$beans = new Ham('beans');
$beans->route('/', function($app) {
return "Beans home.";
});
$beans->route('/baked', function($app) {
return "Yum!";
});
$app = new Ham('example');
$app->route('/', function($app) {
return "App home.";
});
$app->route('/beans', $beans);
$app->run();
require 'ham/ham.php';
$beans = new Ham('beans');
$beans->route('/', function($app) {
return "Beans home.";
});
$app->onError(function(){
return "Burnt Bacon.";
}, "Error message can go here.");
$app->run();
Output:, (*9)
Beans home., (*10)
Yum!, (*11)
App home., (*12)
Burnt Bacon., (*13)
Have a gander at the example application for more details., (*14)
PHP Microframework for use with whatever you like.
BSD-2-Clause
microframework router