Skip to content

JohnMurray/pinatra

Repository files navigation

Pinatra

Update: I finished everything that I had planned to do... So, unless someone else finds this project interesting, I believe that I am done working on it for now. Mainly because there are better/more-mature projects out there.

If the name of this project isn't enough to let you know what it is, this is a Sinatra clone in PHP. Currently this is not a serious project, just a little something for me to try and learn a little more about PHP.

My background is mainly in Ruby and I have a strong love for Sinatra. So, I'm taking about the task to implement the basic feature-set that is present in Sinatra. Mainly the minimalistic route matching and hooks that Sinatra exposes for whipping up dandy little web-apps/api's very quickly.

Getting Started

A simple hello-world example in good 'ole Sinatra fashion:

# index.php
require 'pinatra.php';

Pinatra::get('/hi', function () { return 'Hello World!'; });
Pinatra::run();
php -S 0.0.0.0:8181

Before hooks:

// before everything, set a custom header
Pinatra::before('*', function () { header("MyApp: v${version}"); });

// before user's view their profile, force an update of
// their stream (silly example)
Pinatra::before('/user-profile/:id', function($id) {
  update_user_stream($id);
});

After hooks:

// update site's hit-counter (also silly, but you get the point right?)
Pinatra::after('*', function () {
  update_site_hit_counter();
});

Compatability

This little framework is only compatible with PHP v5.4.x since it was just for fun and I don't care about any sort of backwards compatability.

On the Calendar

The items that I will be adding/implementing next are (roughly) as follows:

  • Parametric URIs (variables actually passed to the handler functions)
  • Refactoring of handle_request function
  • Configuration blocks
  • Testing before and after hooks (working)
  • POST functionality
  • PUT functionality
  • DELETE functionality
  • HEAD functionality

Contributing

This project is dead.

About

Sinatra clone in PHP

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages