Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

PHP Microframework

License

NotificationsYou must be signed in to change notification settings

radiosilence/Ham

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

99 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Now includes tests!

PHP Microframework for use with whatever you like. Basically just a fast routerwith nice syntax, and a cache singleton. Will add more things as I go, likeperhaps an extension system, autoloader and some other stuff to make developingin PHP less irritating than it currently is.

Routes are converted to regex and cached so this process does not need tohappen every request. Furthermore, the resolved route for a given URI is alsocached so on most requests thare is no regex matching involved.

There is also now the ability to mount apps on routes within apps, so one couldmake an administrator app, then mount it on the main app at /admin.

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 cachingwith tiny TTLs to share the results of operations like route resolutionbetween requests.

Note: PHP already has many of the features that many microframeworks have, suchas session handling, cookies, and templating. An aim of this project is toencourage 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 withthe way I like things.

Note: For maximum speed gains, use the XCache extension because that supportscaching of closures, unlike APC.

Goals

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

Inspired entirely by Flask.

Requirements

  • PHP 5.3
  • XCache (preferred) or APC (still optional)
  • Requests pointed at file that you put the app in (eg.index.php).

Hello World

require'../ham/ham.php';$app =newHam('example');$app->route('/',function($app) {return'Hello, world!';});$app->run();

More Interesting Example

require'../ham/ham.php';$app =newHam('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();

Multiple apps mounted on routes!

require'../ham/ham.php';$beans =newHam('beans');$beans->route('/',function($app) {return"Beans home.";});$beans->route('/baked',function($app) {return"Yum!";});$app =newHam('example');$app->route('/',function($app) {return"App home.";});$app->route('/beans',$beans);$app->run();

Custom Error Handeling

require'ham/ham.php';$beans =newHam('beans');$beans->route('/',function($app) {return"Beans home.";});$app->onError(function(){return"Burnt Bacon.";},"Error message can go here.");$app->run();

Output:

/beans/

Beans home.

/beans/baked

Yum!

/

App home.

/definitely_not_the_page_you_were_looking_for

Burnt Bacon.

Have a gander at the example application for more details.

To-Dos

  • Nice logging class and logging support with error levels, e-mailing, etc.
  • 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

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors11


[8]ページ先頭

©2009-2025 Movatter.jp