← all projects

pipeline

A micro web framework that stacks callbacks
repo framework php

Codename Pipeline

Can a web frameworks be as simple as a stack of callbacks? Attach functions before and after others to process the request and prepare the response.

Request > stuff > datastore > stuff > Response

<?php
require_once( '__autoload.php' );

$pipeline = new Pipeline();
$pipeline->add( 'router' );
$pipeline->add_before( 'prep_data', 'router' );

function router( &$data ) {
	$r = new Router( $data );
	$r->add( [ '/hello' => 'hello_view' ] );
}

function prep_data( &$data ) {
	$data['name'] = 'Bob1';
}

function hello_view( $data ) {
	echo 'hello ' . $data['name'];
}

Philosophy

The idea is to end up somewhere between ASP.NET MVC setup and WordPress action/filter/hooks but in an orderly fashion. This allows a micro framework to expose points for functionality to hook into.

The problem with the WordPress way is that code is all over the place, hooking into a multitude of places. The problem with ASP.NET MVC is that too much plumbing and interfaces are required.

Let's see if a micro solution is possible.

I'm still figuring out the rest.

cd src
php -S localhost:8080
open http://localhost:8080/hello # hello Bob