GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - designcise/bitframe: PHP PSR-15 / PSR-7 middleware dispatcher microframework

BranchesTags
Open more actions menu

Latest commit

 

History

63 Commits
63 Commits

Folders and files

NameName
Last commit message
Last commit date
.github
.github
 
 
src
src
 
 
test
test
 
 
.gitattributes
.gitattributes
 
 
.gitignore
.gitignore
 
 
CONTRIBUTING.md
CONTRIBUTING.md
 
 
LICENSE.md
LICENSE.md
 
 
README.md
README.md
 
 
composer.json
composer.json
 
 
composer.lock
composer.lock
 
 
phpstan.neon
phpstan.neon
 
 
phpunit.xml
phpunit.xml
 
 

Repository files navigation

CI Maintainability Code Coverage

BitFrame PHP Microframework

A highly customizable PSR-15 / PSR-7 compatible middleware-based microframework for PHP that comes bundled with a simple PSR-11 based DI container for sharing services and data across the application. It is:

  1. Easy-to-learn and intuitive;
  2. Standards-based;
  3. Simple by design;
  4. Free of unnecessary bloat;
  5. Non-intrusive;
  6. Customizable, modular and easy-to-scale.

Prerequisites

  1. PHP 8.2+;
  2. Server with URL Rewriting (such as Apache, Nginx, etc.).

How to Get Started?

You can get started in a few simple steps:

  1. Setup your environment;
  2. Install composer dependencies;
  3. Create your first "Hello World" app.

For a complete example, have a look at the simple dockerized boilerplate.

1. Setup Your Environment

You can refer to the following minimal Apache and Nginx configurations to get started:

Apache

Create an .htaccess file with at least the following code:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [QSA,L]

This sets the directive in Apache to redirect all Http requests to a front controller index.php file in which you can write your main application code.

Nginx

A configuration like the following in Nginx will help you set the directive to rewrite path to your application front controller (i.e. index.php):

server {
  listen 80;
  server_name 127.0.0.1;

  root /var/www/html/public;
  index index.php;

  location / {
    try_files $uri $uri/ /index.php$is_args$args;
  }

  location ~ \.php$ {
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_pass app:9000;
    fastcgi_index index.php;
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_param PATH_INFO $fastcgi_path_info;
  }

  access_log /var/log/nginx/access.log;
  error_log  /var/log/nginx/error.log;
}

Remember to make changes according to your project setup. For example, ensure that listen, root, fastcgi_pass, *_log, etc. are setup correctly according to your project.

2. Install Composer Dependencies

You can use composer require like so:

$ composer require "designcise/bitframe":^4.0

Or, alternatively, you can add the package dependency in your composer.json file.

Please note that you must include a PSR-17 factory in your composer dependencies. nyholm/psr7 and guzzle/psr7 are good examples of these — if you include either of these, they're automatically picked up by BitFrame. For any other PSR-17 factory implementation, you can add it add via \BitFrame\Factory\HttpFactory::addFactory() method before you instantiate \BitFrame\App.

3. Create Your First "Hello World" App

If you have ever used a middleware based framework, you will feel at ease. A "Hello World" app would look something like the following:

<?php

require 'vendor/autoload.php';

use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;
use BitFrame\App;
use BitFrame\Emitter\SapiEmitter;

// 1. Instantiate the App
$app = new App();

$middleware = function (ServerRequestInterface $request, RequestHandlerInterface $handler) {
    $response = $handler->handle($request);
    $response->getBody()->write('Hello World!');
    return $response;
};

// 2. Add middleware
$app->use([
    SapiEmitter::class,
    $middleware,
]);

// 3. Run the application
$app->run();

From the code above you can see that the application uses two middlewares:

  1. A PSR-15 middleware \BitFrame\Emitter\SapiEmitter (that comes bundled with BitFrame package) which allows to emit the HTTP Response to the requesting user-agent (such as a web browser);
  2. A closure middleware used to write Hello World! to the HTTP response stream.

This is of course a very basic example. In a real-world application, the setup would be much more complex than this. For example, you could extend the functionality by using an additional PSR-15 middleware such as a router, error handler, etc. For suggestions on how to go about designing your application (and to get started quickly), have a look at the simple dockerized boilerplate example.

Tests

To run the tests you can use the following commands:

Command Type
composer test PHPUnit tests
composer style CodeSniffer
composer style-fix CodeSniffer Fixer
composer md MessDetector
composer check PHPStan

Contributing

Please see CONTRIBUTING for details.

  • File issues at https://github.com/designcise/bitframe/issues
  • Issue patches to https://github.com/designcise/bitframe/pulls

License

Please see License File for licensing information.

About

PHP PSR-15 / PSR-7 middleware dispatcher microframework

www.bitframephp.com

Topics

microframeworkmiddleware-frameworkphppsr-15psr-7

Resources

Readme
License

Contributing

Contributing
Activity

Stars

23 stars

Watchers

4 watching

Forks

4 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.