bittyphp / bitty
A tiny and simple PHP framework. No fuss, no muss, no coconuts.
Requires
- php: >=7.1.0
- bittyphp/container: ^3.0
- bittyphp/event-manager: ^2.0
- bittyphp/http: ^2.0
- bittyphp/middleware: ^2.0
- bittyphp/router: ^3.0
- container-interop/service-provider: ^0.4
- psr/container: ^1.0
- psr/http-message: ^1.0
Requires (Dev)
- bizurkur/coding-standard: ^1.0
- codacy/coverage: ^1.4
- infection/infection: ^0.12.0
- jakub-onderka/php-parallel-lint: ^1.0
- localheinz/composer-normalize: ^1.1
- phing/phing: ^2.16
- phpstan/phpstan: ^0.10.7
- phpstan/phpstan-deprecation-rules: ^0.10.2
- phpstan/phpstan-phpunit: ^0.10.0
- phpstan/phpstan-strict-rules: ^0.10.1
- phpunit/phpunit: ^7.0
- squizlabs/php_codesniffer: ^3.0
This package is auto-updated.
Last update: 2023-04-29 01:04:19 UTC
README
A tiny and simple PHP framework. No fuss, no muss, no coconuts.
Work in Progress
As a warning, this is a work in progress. Things may break randomly. Use at your own risk.
Purpose
Bitty began as a learning experiment, but evolved into the desire to build something that followed PSRs without adding too many non-standard additions. Several libraries have PSR-compliant implementations, but they add extra methods and unwanted dependencies. I wanted something without the bloat - something that was "itty bitty" (hence the name Bitty).
Installation
It's best to install Bitty using Composer.
$ composer require bittyphp/bitty
Since Bitty doesn't force what view to use or what kind of controller you use, you may or may not want to also require the following:
# An abstract controller with common methods added for convenience $ composer require bittyphp/controller # A view based on the Twig engine $ composer require bittyphp/view-twig
There's view layers for Twig, Mustache, Latte, and Plates. If those aren't enough, you can also make your own.
Setup
Starting with Bitty is easy. The main application has shortcuts for adding routes, managing middleware, accessing the container, and registering services.
Adding Routes
There are helper methods for adding routes for get
, post
, put
, patch
, delete
, options
, and a generic map
for supporting multiple methods on the same route.
See Bitty's Router docs for more details.
<?php require(dirname(__DIR__).'/vendor/autoload.php'); use Bitty\Application; use Bitty\Http\Response; use Psr\Http\Message\ServerRequestInterface; $app = new Application(); $app->get('/', function (ServerRequestInterface $request) { return new Response('Hello, world!'); }); $app->patch('/foo', function (ServerRequestInterface $request) { return new Response('PATCHed /foo'); }); $app->map(['GET', 'POST'], '/foo', function (ServerRequestInterface $request) { return new Response('I support GET and POST'); }); $app->run();
Managing Middleware
Bitty supports any PSR-15 middleware. See the Middleware docs for more info.
<?php require(dirname(__DIR__).'/vendor/autoload.php'); use Bitty\Application; use Psr\Http\Server\MiddlewareInterface; $app = new Application(); /** @var MiddlewareInterface */ $myMiddleware = ...; $app->add($myMiddleware); $app->run();
Accessing the Container
Bitty comes with a PSR-11 container. See the Container docs for how you can manage it.
<?php require(dirname(__DIR__).'/vendor/autoload.php'); use Bitty\Application; $app = new Application(); $container = $app->getContainer(); $app->run();
Registering Services
You can easily register services with the container using any service provider implementation.
<?php require(dirname(__DIR__).'/vendor/autoload.php'); use Bitty\Application; use Interop\Container\ServiceProviderInterface; $app = new Application(); /** @var ServiceProviderInterface */ $myProvider = ...; $app->register($myProvider); $app->run();
Standards
Bitty adheres the following framework standards:
- PSR-1: Basic Coding Standard
- PSR-2: Coding Style Guide
- PSR-4: Autoloading Standard
- PSR-7: HTTP Message Interface
- PSR-11: Container Interface
- PSR-15: HTTP Middleware
- PSR-17: HTTP Factories
It also follows (or closely follows) some proposed standards:
Lacking
Bitty does not have built-in support for the following. At least not yet.
- PSR-3: Logger Interface
- PSR-6: Caching Interface
- Probably won't support ever, but maybe PSR-16 instead.
- PSR-13: Hypermedia Links
- PSR-16: Simple Cache
Credits
Bitty follows some design ideas from Symfony, specifically in the realm of security. The main application follows a similar design as Slim and Silex (and possibly others).