2017 © Pedro PelĂĄez
 

library php-server

A minimal routable HTTP middleware framework for PHP.

image

mariuslundgard/php-server

A minimal routable HTTP middleware framework for PHP.

  • Sunday, October 19, 2014
  • by mariuslundgard
  • Repository
  • 1 Watchers
  • 0 Stars
  • 36 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 5 Versions
  • 0 % Grown

The README.md

php-server

Build Status Coverage Status, (*1)

Latest Stable Version, (*2)

Features

  • Routable middleware (application layers)
  • Routable controller actions

Examples

This is the canonical Hello World example:, (*3)

<?php 

require 'vendor/autoload.php';

$app = (new Server\Module())
    ->map([
        'fn' => function ($req, $res) {
            $res->write('

Hello, world

'); } ]) ->call() // calls the application ->send(); // outputs the headers and response body

This example shows how to use middleware and map controllers:, (*4)

```php <?php, (*5)

require 'vendor/autoload.php';, (*6)

class HeaderFilter extends Server\Layer { public function call(Server\Request $req = null, Server\Error $err = null) { $res = parent::call($req, $err);, (*7)

    $res->body = '<h1>'.$res->body.'</h1>';

    return $res;
}

}, (*8)

class FrontController extends Server\Controller { public function index() { return 'Hello, world!'; } }, (*9)

$app = new Server\Module();, (*10)

$app->employ([ 'class' => 'HeaderFilter', ]);, (*11)

$app->map([ 'controller' => 'FrontController', ]);, (*12)

$app->call()->send(); // outputs:, (*13)

Hello, world!

The Versions