You are viewing the website for BitFrame v1. BitFrame v2.0 was released on 11-May-2020 — new documentation and website will be available soon!


An overview of the BitFrame Application object



In BitFrame, an application (\BitFrame\Application) does the following:

  • Store and relay HTTP Request/Response to the middleware dispatcher;
  • Immediately run middleware, or queue middleware to run at a later time;
  • Share HTTP Request/Response between different queues of middleware, or optionally reset them;
  • Store routes — shared as an attribute (\BitFrame\Router\RouteCollectionInterface::class) with the HTTP Request;
  • Store arbitrary data — shared as an attribute (\BitFrame\Data\ApplicationData::class) with the HTTP Request;
  • Control whether the middleware are dispatched immediately or when the run() method is called;
  • Retrieve the URL endpoints and query string.

Create an Application Instance:

A BitFrame application instance can be created with the following code:

$app = new \BitFrame\Application();

\BitFrame\Application only accepts a configuration array as argument:

$config = [
    DispatcherInterface::class => null,

    ServerRequestInterface::class => null,
    ResponseInterface::class => null,

    RouteCollectionInterface::class => null

$app = new \BitFrame\Application($config);

By specifying a value for any of the properties in the configuration array, you can choose to override the corresponding default component used by the application. For instance:

use \GuzzleHttp\Psr7\ServerRequest;
use \GuzzleHttp\Psr7\Response;

$config = [
    ServerRequestInterface::class => new ServerRequest('GET', ''),
    ResponseInterface::class => new Response

$app = new \BitFrame\Application($config);

The code above will override the default HTTP Request/Response handlers with the ones provided.

Out-of-the-box Zend Diactoros and GuzzleHttp are supported by default when \BitFrame\Factory\HttpMessageFactory is used to create the request/response objects. Internally the \BitFrame\Application uses \BitFrame\Factory\HttpMessageFactory so there's no need to explicitly call it.

Components specified via \BitFrame\Factory\ApplicationFactory or \BitFrame\Factory\HttpMessageFactory will ONLY be used if the components are unspecified (i.e. null) in the \BitFrame\Application configuration array.


Let us know if you have something to say or add