Skip to content

odino/exphpress

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Exphpress

Build Status

The missing, elegant, productive microframework for PHP, inspired by ExpressJS.

Because PHP is cool too.

Example

The very least you need:

<?php

$app = Exphpress\app();

$app->listen(function($req, $res){
    $date = new \DateTime();
    
    $res->setContent("Today is " . $date->format('l, jS \o\f F Y'));
});

This will return, for every request, something like Today is Sunday, 13th of July 2014,; if you want to see it in action clone this repository and run php -S localhost:4000 examples/simple.php.

Getting fancy

Matching a GET request is quite simple:

<?php

$app = Exphpress\app();

$app->get("/call-me-maybe/{name}", function($req, $res){
    $res->setContent("Hey, I just matched you, and this is crazy...");
});

The above route will be matched when we issue a GET request to our webserver that matches the path /call-me-maybe/{name}.

The same can be done for post and all other HTTP methods.

Write your own middleware

Middlewares play a big part in a microframework's architecture:

$app->uses(function($req, $res, $next){
    if ($todayIsABadDay) {
        $res->setStatusCode(403);
        $res->setContent(null);
    } else {
        $next();
    }
});

As you probably understood, the $next is a callback that invokes the following middleware, which means that you concatenate them at will (ie. look at this test).

Installation

Exphpress is available through composer (how else?!?!).

Tests

They run on travis through phpspec: if you want to contribute or hack around exphpress simply clone this repository and check into greenland with a:

./vendor/bin/phpspec run

License

For those who care, exphpress is release under the MIT license.

The hell, why?

There's Silex, I know, but I couldn't resist.

About

The missing, elegant, productive microframework for PHP, inspired by ExpressJS.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages