Skip to content

Commit aa18982

Browse files
authored
v2.0.0 (#1)
1 parent 458853e commit aa18982

File tree

142 files changed

+7594
-7357
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

142 files changed

+7594
-7357
lines changed

.gitattributes

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,9 @@
11
# Auto detect text files and perform LF normalization
22
* text=auto
3+
4+
/.gitattributes export-ignore
5+
/.gitignore export-ignore
6+
/.travis.yml export-ignore
7+
/phpunit.xml export-ignore
8+
/phpstan.neon export-ignore
9+
/test export-ignore

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/vendor/
2+
/.idea
3+
.DS_Store
4+
*.cache
5+
composer.lock
6+
clover.xml

.travis.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
cache:
2+
apt: true
3+
directories:
4+
- $HOME/.composer/cache/files
5+
6+
language: php
7+
8+
php:
9+
- 7.4.0
10+
11+
before_script:
12+
- travis_retry composer install --no-interaction --no-suggest --prefer-source
13+
- travis_retry composer require nyholm/psr7:^1.2
14+
15+
script:
16+
- vendor/bin/phpunit --configuration phpunit.xml --coverage-clover=coverage.xml
17+
18+
after_success:
19+
- bash <(curl -s https://codecov.io/bash)
20+
21+
branches:
22+
only:
23+
- 2.x

CONTRIBUTING.md

100644100755
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ It is very important to separate new features or improvements into separate feat
1010

1111
## Style Guide
1212

13-
All pull requests must adhere to the PSR-2 standard.
13+
All pull requests must adhere to the PSR-12 standard.
1414

1515
## Unit Testing
1616

LICENSE.md

100644100755
Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,43 @@
1-
Portions of the BitFrame framework incorporates the work by (as provided under the MIT lincense):
1+
# License
22

3-
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
4-
* Copyright (c) 2012 PHP Framework Interoperability Group
5-
* Copyright (c) 2017 benliev
6-
* Copyright (c) 2011-2017 Josh Lockhart
7-
* Copyright (c) 2017 Phil Bennett <philipobenito@gmail.com>
3+
### Copyright (c) 2017-2020 Daniyal Hamid (https://designcise.com)
84

9-
Portions of the BitFrame framework incorporates the work by (as provided under the New BSD license):
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
106

11-
* Copyright (c) 2015-2017 Zend Technologies USA Inc. (http://www.zend.com)
7+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
128

13-
All other copyright for the BitFrame framework are held by (as provided under the MIT lincense):
9+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1410

15-
* Copyright (c) 2017-2018 Daniyal Hamid (https://designcise.com)
11+
### Third-party software used in BitFrame Microframework
1612

17-
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
13+
Portions of the BitFrame microframework either build-upon or take inspiration from the work done by:
1814

19-
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
15+
- **PHP Framework Interoperability Group**
16+
* Credit For: Interoperability Interfaces
17+
* Copyright (c) 2012 PHP Framework Interoperability Group
18+
* MIT License
19+
20+
- **Zend Technologies USA Inc.**
21+
* Credit For: Emitter, Renderer & Http Factory Functions
22+
* Copyright (c) 2015-2017 Zend Technologies USA Inc. (http://www.zend.com)
23+
* New BSD license
24+
25+
- **Oscar Otero Marzoa**
26+
* Credit For: HttpFactory
27+
* Copyright (c) 2018 Oscar Otero Marzoa (https://oscarotero.com)
28+
* MIT License
29+
30+
- **Guzzle Http**
31+
* Credit For: Http Factory Functions
32+
* Copyright (c) 2015 Michael Dowling, https://github.com/mtdowling <mtdowling@gmail.com>
33+
* MIT License
34+
35+
- **Phil Bennett**
36+
* Credit For: Router
37+
* Copyright (c) 2017 Phil Bennett <philipobenito@gmail.com>
38+
* MIT License
2039

21-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
40+
- **Slim Framework**
41+
* Credit For: Http Decorators
42+
* Copyright (c) 2015 Slim Framework
43+
* MIT License

README.md

100644100755
Lines changed: 86 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,134 @@
11
# BitFrame PHP Microframework
22

3-
* Highly customizable and event driven PSR-15 and PSR-7 compatible middleware microframework for PHP;
3+
[![codecov](https://codecov.io/gh/designcise/bitframe/branch/2.x/graph/badge.svg)](https://codecov.io/gh/designcise/bitframe)
4+
[![Build Status](https://travis-ci.org/designcise/bitframe.svg?branch=2.x)](https://travis-ci.org/designcise/bitframe)
5+
6+
## At-a-glance
7+
8+
* Highly customizable PSR-15 and PSR-7 compatible middleware-based microframework for PHP;
9+
* Simple PSR-11 based dependency injection container;
410
* Simple to learn, use and implement;
511
* Follows the [PSR standards](http://www.php-fig.org/) and integrates the best of existing opensource frameworks wherever possible.
612

7-
### Why use BitFrame?
13+
## Why use BitFrame?
814

915
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.
1016

1117
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:
1218

13-
1. Be well-documented and intuitive;
14-
1. Facilitate the developer and be nonintrusive;
15-
1. Be free of unnecessary bloat;
16-
1. Promote modularity to allow any component of the framework to be easily replaced;
17-
1. Provide the flexibility of using existing PSR-15 / PSR-7 middlewares that plug right in easily;
18-
1. Provide the ability to share variables and application data seamlessly across all the middlewares.
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.
1925

20-
### Installation
26+
## Installation
2127

2228
Install BitFrame and its required dependencies using composer:
2329

2430
```
25-
$ composer require designcise/bitframe
31+
$ composer require "designcise/bitframe"
2632
```
2733

28-
Please note that BitFrame requires PHP 7.1.0 or newer.
34+
Please note that BitFrame v2+ requires PHP 7.4.0 or newer.
35+
36+
## Quickstart
37+
38+
Get started quickly by using the boilerplate code at https://github.com/designcise/bitframe-boilerplate.
2939

30-
### Quickstart
40+
### Apache
3141

3242
After you have installed the required dependencies specific to your project, create an `.htaccess` file with at least the following code:
3343

34-
```
44+
```apacheconfig
3545
RewriteEngine On
3646
RewriteCond %{REQUEST_FILENAME} !-f
3747
RewriteCond %{REQUEST_FILENAME} !-d
3848
RewriteRule ^ index.php [QSA,L]
3949
```
4050

41-
This sets the directive in apache to redirect all Http Requests to `index.php` in which we can write our application code. For example:
51+
This sets the directive in apache to redirect all Http Requests to `index.php` in which we can write our application code.
52+
53+
### Nginx
4254

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`):
56+
57+
```
58+
server {
59+
listen 80;
60+
server_name 127.0.0.1;
61+
62+
root /var/www/html/public;
63+
index index.php;
64+
65+
location / {
66+
try_files $uri $uri/ /index.php$is_args$args;
67+
}
68+
69+
location ~ \.php$ {
70+
fastcgi_split_path_info ^(.+\.php)(/.+)$;
71+
fastcgi_pass app:9000;
72+
fastcgi_index index.php;
73+
include fastcgi_params;
74+
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
75+
fastcgi_param PATH_INFO $fastcgi_path_info;
76+
}
77+
78+
access_log /var/log/nginx/access.log;
79+
error_log /var/log/nginx/error.log;
80+
}
4381
```
82+
83+
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+
85+
### Example
86+
87+
For a full application example, please [check out the boilerplate](https://github.com/designcise/bitframe-boilerplate).
88+
89+
```php
4490
<?php
4591

4692
require 'vendor/autoload.php';
4793

48-
$app = new \BitFrame\Application();
94+
use Psr\Http\Message\ServerRequestInterface;
95+
use Psr\Http\Server\RequestHandlerInterface;
96+
use BitFrame\App;
97+
use BitFrame\Emitter\SapiEmitter;
4998

50-
$app->addMiddleware([
51-
\BitFrame\Message\DiactorosResponseEmitter::class,
52-
function ($request, $response, $next) {
53-
$response->getBody()->write('Hello World!');
99+
$app = new App();
54100

55-
return $next($request, $response);
56-
}
101+
$middleware = function (ServerRequestInterface $request, RequestHandlerInterface $handler) {
102+
$response = $handler->handle($request);
103+
$response->getBody()->write('Hello World!');
104+
return $response;
105+
};
106+
107+
$app->use([
108+
SapiEmitter::class,
109+
$middleware,
57110
]);
58111

59112
$app->run();
60113
```
61114

62115
From the code above you can see that we're using two middlewares:
63116

64-
1. A PSR-15 based wrapper of [Zend Diactoros](https://github.com/zendframework/zend-diactoros) that allows us to emit the HTTP Response to the requesting user-agent (such as a web browser);
65-
1. A closure used to write `Hello World!` to the HTTP Response.
66-
67-
Similar to the `\BitFrame\Message\DiactorosResponseEmitter` middleware package [we've developed some essential PSR-15 packages](https://www.bitframephp.com/doc/getting-started/install#how-to-install-project-dependencies-middlewares) that are typically used in API and web app development. These can be added to BitFrame easily as per your project's need and are in no way a hard dependency.
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.
68119

69-
Also note that, apart from these official packages, you can easily use any PSR-15 or PSR-7 based packages, or develop your own.
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/tree/2.x), error handler, etc.
70121

71-
Refer to the [official BitFrame documentation](https://www.bitframephp.com/doc/) to learn more.
122+
## Tests
72123

73-
### Tests
124+
To run the tests you can use the following commands:
74125

75-
To execute the test suite, you will need [PHPUnit](https://phpunit.de/).
126+
| Command | Type |
127+
| ---------------- |:---------------:|
128+
| `composer test` | PHPUnit tests |
129+
| `composer style` | CodeSniffer |
130+
| `composer md` | MessDetector |
131+
| `composer check` | PHPStan |
76132

77133
### Contributing
78134

@@ -83,9 +139,7 @@ Please see [CONTRIBUTING](CONTRIBUTING.md) for details.
83139

84140
### Documentation
85141

86-
Documentation is available at:
87-
88-
* https://www.bitframephp.com/doc/
142+
Complete documentation for v2.0 will be released soon.
89143

90144
### License
91145

composer.json

100755100644
Lines changed: 52 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,54 @@
11
{
2-
"name": "designcise/bitframe",
3-
"version": "1.1.5",
4-
"description": "PHP PSR-15 / PSR-7 middleware dispatcher microframework",
5-
"type": "library",
6-
"keywords": ["Designcise", "BitFrame", "Microframework", "Framework", "Middleware Dispatcher", "PSR-7", "PSR-15"],
7-
"license": "(MIT and BSD-3-Clause)",
8-
"authors": [
9-
{
10-
"name": "Daniyal Hamid",
11-
"homepage": "https://www.designcise.com/"
12-
}
13-
],
14-
"require": {
15-
"php": "^7.1.0",
16-
"psr/http-factory": "^1.0",
17-
"psr/http-message": "^1.0",
18-
"psr/http-server-handler": "~1.0",
19-
"psr/http-server-middleware": "~1.0",
20-
"fig/http-message-util": "^1.0"
21-
},
22-
"autoload": {
23-
"files": [
24-
"src/Factory/functions/create_uploaded_file.php",
25-
"src/Factory/functions/marshal_headers_from_sapi.php",
26-
"src/Factory/functions/marshal_method_from_sapi.php",
27-
"src/Factory/functions/marshal_protocol_version_from_sapi.php",
28-
"src/Factory/functions/marshal_uri_from_sapi.php",
29-
"src/Factory/functions/normalize_uploaded_files.php",
30-
"src/Factory/functions/parse_cookie_header.php"
31-
],
32-
"psr-4": {
33-
"BitFrame\\": "src/"
34-
}
35-
},
36-
37-
"require-dev": {
38-
"phpunit/phpunit": "^6.4"
39-
},
40-
"autoload-dev": {
41-
"psr-4": {
42-
"BitFrame\\Test\\": "test/"
43-
},
44-
"files": ["test/Asset/function.php"]
45-
},
46-
47-
"suggest": {
48-
"designcise/bitframe-whoops": "Whoops error handler middleware for BitFrame microframework",
49-
"designcise/bitframe-diactoros": "Zend Diactoros HTTP message middleware for BitFrame microframework",
50-
"designcise/bitframe-fastroute": "Fastroute router middleware for BitFrame microframework",
51-
"designcise/bitframe-leagueplates": "League Plates template renderer for BitFrame microframework"
2+
"name": "designcise/bitframe",
3+
"version": "2.0.0",
4+
"type": "library",
5+
"description": "BitFrame PHP microframework",
6+
"license": "MIT",
7+
"authors": [
8+
{
9+
"name": "Daniyal Hamid",
10+
"homepage": "https://www.designcise.com/"
11+
}
12+
],
13+
"require": {
14+
"php": ">=7.4",
15+
"ext-json": "*",
16+
"psr/container": "^1.0",
17+
"psr/http-server-middleware": "~1.0"
18+
},
19+
"require-dev": {
20+
"phpunit/phpunit": "^8.5",
21+
"mockery/mockery": "^1.3",
22+
"squizlabs/php_codesniffer": "3.*",
23+
"phpmd/phpmd": "@stable",
24+
"phpstan/phpstan": "*"
25+
},
26+
"suggest": {
27+
"ext-libxml": "For out-of-the-box XML support, please install libxml extension",
28+
"ext-simplexml": "For out-of-the-box XML support, please install simplexml extension",
29+
"nyholm/psr7": "Add PSR-7 / PSR-17 based HTTP Messaging support for your App",
30+
"designcise/bitframe-fastroute": "Add routing support to your App"
31+
},
32+
"scripts": {
33+
"style": "vendor/bin/phpcs --standard=PSR12 src",
34+
"check": "vendor/bin/phpstan analyse src --level=5 -c phpstan.neon",
35+
"md": "vendor/bin/phpmd src text cleancode,unusedcode,codesize,design,naming",
36+
"test": "vendor/bin/phpunit --configuration phpunit.xml --testsuite bitframe"
37+
},
38+
"autoload": {
39+
"psr-4": {
40+
"BitFrame\\": "src/"
5241
}
53-
}
42+
},
43+
"autoload-dev": {
44+
"psr-4": {
45+
"BitFrame\\Test\\": "test/"
46+
},
47+
"files": [
48+
"test/Asset/function.php"
49+
]
50+
},
51+
"config": {
52+
"sort-packages": true
53+
}
54+
}

phpstan.neon

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
parameters:
2+
treatPhpDocTypesAsCertain: false
3+
reportStaticMethodSignatures: false

0 commit comments

Comments
 (0)