You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Highly customizable PSR-15 and PSR-7 compatible middleware-based microframework for PHP;
9
-
* Simple PSR-11 based dependency injection container;
10
-
* Simple to learn, use and implement;
11
-
* Follows the [PSR standards](http://www.php-fig.org/) and integrates the best of existing opensource frameworks wherever possible.
4
+
# BitFrame PHP Microframework
12
5
13
-
## Why use BitFrame?
6
+
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:
14
7
15
-
BitFrame's approach of making the middleware dispatcher the core component of the framework encourages the developer to use middleware-based services that plug right-in with ease. This allows for greater flexibility especially in terms of debugging, replacements and updating. While this design pattern may not suit the needs of all projects, it certainly has its advantages for long-term and strategic ones because as they grow in complexity the underlying framework helps keep things well-organized, easy-to-manage and very simple.
8
+
1. Easy-to-learn and intuitive;
9
+
2. Standards-based;
10
+
4. Simple by design;
11
+
5. Free of unnecessary bloat;
12
+
6. Non-intrusive;
13
+
7. Customizable, modular and easy-to-scale.
16
14
17
-
At the core of our development, we've tried very hard to abide by some simple rules that we've mostly found missing in other microframeworks:
15
+
## How to Get Started?
18
16
19
-
1.**Easy-to-learn:** Be well-documented and intuitive;
20
-
1.**Non-intrusive:** Facilitate the developer and not be a nuisance;
21
-
1.**Simple by design:** Encourage flow of development to be simple and easy to read;
22
-
1.**Customizable:** Promote modularity and high customizability;
23
-
1.**Fat-free:** Be free of unnecessary bloat;
24
-
1.**Standards-based:** Be standards-based wherever possible.
17
+
You can get started in a few simple steps:
25
18
26
-
## Installation
19
+
1. Setup your environment;
20
+
2. Install `composer` dependencies;
21
+
3. Create your first "Hello World" app.
27
22
28
-
Install BitFrame and its required dependencies using composer:
23
+
Also, please note the following prerequisites:
29
24
30
-
```
31
-
$ composer require "designcise/bitframe"
32
-
```
25
+
### Prerequisites
33
26
34
-
Please note that BitFrame v3+ requires PHP 8.0.0 or newer.
27
+
1. PHP 8.0+;
28
+
2. Server with URL Rewriting (such as Apache, Nginx, etc.).
35
29
36
-
##Quickstart
30
+
### 1. Setup Your Environment
37
31
38
-
Get started quickly by using the boilerplate code at https://github.com/designcise/bitframe-boilerplate.
32
+
You can refer to the following minimal Apache and Nginx configurations to get started:
39
33
40
-
### Apache
34
+
####Apache
41
35
42
-
After you have installed the required dependencies specific to your project, create an `.htaccess` file with at least the following code:
36
+
Create an `.htaccess` file with at least the following code:
This sets the directive in apache to redirect all Http Requests to `index.php` in which we can write our application code.
45
+
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.
52
46
53
-
### Nginx
47
+
####Nginx
54
48
55
-
A configuration like the following in nginx will help you set the directive to rewrite path to our application front controller (i.e. `index.php`):
49
+
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`):
56
50
57
51
```
58
52
server {
@@ -82,9 +76,21 @@ server {
82
76
83
77
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.
84
78
85
-
### Example
79
+
### 2. Install Composer Dependencies
86
80
87
-
For a full application example, please [check out the boilerplate](https://github.com/designcise/bitframe-boilerplate).
81
+
You can use `composer require` like so:
82
+
83
+
```
84
+
$ composer require "designcise/bitframe":^3.5
85
+
```
86
+
87
+
Or, alternatively, you can add the package dependency in your `composer.json` file.
88
+
89
+
Please note that you must include a PSR-17 factory in your composer dependencies. [nyholm/psr7](https://github.com/Nyholm/psr7/blob/master/src/Factory/Psr17Factory.php) and [guzzle/psr7](https://github.com/guzzle/psr7/blob/master/src/HttpFactory.php) 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`.
90
+
91
+
### 3. Create Your First "Hello World" App
92
+
93
+
If you have ever used a middleware based framework, you will feel at ease. A "Hello World" app would look something like the following:
88
94
89
95
```php
90
96
<?php
@@ -96,6 +102,7 @@ use Psr\Http\Server\RequestHandlerInterface;
96
102
use BitFrame\App;
97
103
use BitFrame\Emitter\SapiEmitter;
98
104
105
+
// 1. Instantiate the App
99
106
$app = new App();
100
107
101
108
$middleware = function (ServerRequestInterface $request, RequestHandlerInterface $handler) {
@@ -104,31 +111,34 @@ $middleware = function (ServerRequestInterface $request, RequestHandlerInterface
104
111
return $response;
105
112
};
106
113
114
+
// 2. Add middleware
107
115
$app->use([
108
116
SapiEmitter::class,
109
117
$middleware,
110
118
]);
111
119
120
+
// 3. Run the application
112
121
$app->run();
113
122
```
114
123
115
-
From the code above you can see that we're using two middlewares:
124
+
From the code above you can see that the application uses two middlewares:
116
125
117
-
1. A PSR-15 middleware `\BitFrame\Emitter\SapiEmitter` that allows us to emit the HTTP Response to the requesting user-agent (such as a web browser);
118
-
1. A closure middleware used to write `Hello World!` to the HTTP Response.
126
+
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);
127
+
2. A closure middleware used to write `Hello World!` to the HTTP response stream.
119
128
120
-
This is of course a very basic example. You could extend the functionality by using additional middleware such as a [router](https://github.com/designcise/bitframe-fastroute), error handler, etc.
129
+
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](https://github.com/designcise/bitframe-fastroute), [error handler](https://github.com/designcise/bitframe-whoops), 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](https://github.com/designcise/bitframe-boilerplate).
121
130
122
131
## Tests
123
132
124
133
To run the tests you can use the following commands:
125
134
126
-
| Command | Type |
127
-
| ---------------- |:---------------:|
128
-
|`composer test`| PHPUnit tests |
129
-
|`composer style`| CodeSniffer |
130
-
|`composer md`| MessDetector |
131
-
|`composer check`| PHPStan |
135
+
| Command | Type |
136
+
| ------------------- |:----------------:|
137
+
|`composer test`| PHPUnit tests |
138
+
|`composer style`| CodeSniffer |
139
+
|`composer style-fix`| CodeSniffer Fixer|
140
+
|`composer md`| MessDetector |
141
+
|`composer check`| PHPStan |
132
142
133
143
### Contributing
134
144
@@ -137,10 +147,6 @@ Please see [CONTRIBUTING](CONTRIBUTING.md) for details.
137
147
* File issues at https://github.com/designcise/bitframe/issues
138
148
* Issue patches to https://github.com/designcise/bitframe/pulls
139
149
140
-
### Documentation
141
-
142
-
Complete documentation for v3 will be released soon.
143
-
144
150
### License
145
151
146
152
Please see [License File](LICENSE.md) for licensing information.
0 commit comments