Skip to content

encodes1/Ham

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 

Repository files navigation

Ham

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.

Routes are converted to regex and cached so this process does not need to happen every request.

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.

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.

Goals

  • Make pretty much anything I/O related cached with XCache/APC (whichever is installed) in order to prevent excessive disk usage or path searching on lots of requests.
  • Provide a succinct syntax that means less magic and less code to read through and learn, without compromising speed or code length, by using native PHP methods and features.
  • Promote a simple, flat way of building applications that don't need massive levels of abstraction.
  • Encourage use of excellent third-party libraries such as Doctrine to prevent developers writing convoluted, unmaintainable code that people like me have to pick up and spend hours poring over just to get an idea of what on earth is going on.
  • Define and document development patterns that allow for new developers to get up to speed quickly and write new code that isn't hacky.

Inspired entirely by Flask.

Hello World

require '../ham/ham.php';

$app = new Ham();

$app->route('/', function($app) {
    return 'Hello, world!';
});

$app->run();

More Interesting Example

require '../ham/ham.php';

$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();

Have a gander at the example application for more details.

To-Dos

  • Sub-application mounting (ala Flask "Blueprints").
  • Sanitisation solution.
  • CSRF tokens
  • Extension API

Extension Ideas

  • Form generation (3rd-party? Phorms)
  • ORM integration (most likely Doctrine)
  • Auth module (using scrypt or something)
  • Admin extension

About

PHP Microframework

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published