Skip to content

Commit 27387ba

Browse files
authored
Merge pull request #1 from designcise/2.x
v2.0.0
2 parents 8221ca2 + 189e89e commit 27387ba

18 files changed

+1997
-410
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: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/vendor/
2+
/.idea
3+
.DS_Store
4+
*.cache
5+
composer.lock

.travis.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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+
14+
script:
15+
- vendor/bin/phpunit --configuration phpunit.xml --coverage-clover=coverage.xml
16+
17+
after_success:
18+
- bash <(curl -s https://codecov.io/bash)
19+
20+
branches:
21+
only:
22+
- 2.x

LICENSE.md

100644100755
Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,18 @@
1-
Copyright (c) 2017-2018 Daniyal Hamid (https://designcise.com).
1+
# License
2+
3+
### Copyright (c) 2017-2020 Daniyal Hamid (https://designcise.com)
24

35
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:
46

57
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
68

7-
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.
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.
10+
11+
### Third-party software used in BitFrame Microframework
12+
13+
Portions of this package either build-upon or take inspiration from the work done by:
14+
15+
- **FastRoute Router**
16+
* Credit For: FastRoute Library
17+
* Copyright (c) 2013 by Nikita Popov.
18+
* MIT License

README.md

100644100755
Lines changed: 36 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,65 @@
1-
# BitFrame\Router\FastRouteRouter
1+
# BitFrame\FastRoute
2+
3+
[![codecov](https://codecov.io/gh/designcise/bitframe-fastroute/branch/2.x/graph/badge.svg)](https://codecov.io/gh/designcise/bitframe-fastroute)
4+
[![Build Status](https://travis-ci.org/designcise/bitframe-fastroute.svg?branch=2.x)](https://travis-ci.org/designcise/bitframe-fastroute)
25

36
FastRoute wrapper class to manage http routes as a middleware.
47

5-
### Installation
8+
## Installation
9+
10+
Install using composer:
611

7-
See [installation docs](https://www.bitframephp.com/middleware/router/fastroute) for instructions on installing and using this middleware.
12+
```
13+
$ composer require designcise/bitframe-fastroute
14+
```
815

9-
### Usage Example
16+
Please note that this package requires PHP 7.4.0 or newer.
17+
18+
## Usage Example
1019

1120
```
12-
use \BitFrame\Router\FastRouteRouter;
21+
use BitFrame\App;
22+
use BitFrame\Emitter\SapiEmitter;
23+
use BitFrame\FastRoute\Router;
1324
1425
require 'vendor/autoload.php';
1526
16-
$app = new \BitFrame\Application;
27+
$app = new App();
28+
$router = new Router();
1729
18-
$app->map(['GET', 'POST'], '/test', function ($request, $response, $next) {
30+
$router->map(['GET', 'POST'], '/test', function ($request, $handler) {
31+
$response = $handler->handle($request);
1932
$response->getBody()->write('Test Page');
20-
2133
return $response;
2234
});
2335
2436
$app->run([
25-
/* In order to output response from the router (or router middleware),
26-
* make sure you include a response emitter middleware, for example:
27-
* \BitFrame\Message\DiactorosResponseEmitter::class, */
28-
// router should normally be the last middleware to run
29-
FastRouteRouter::class
37+
SapiEmitter::class,
38+
$router,
39+
// ...
3040
]);
3141
```
3242

33-
### Tests
43+
## Tests
44+
45+
To run the tests you can use the following commands:
3446

35-
To execute the test suite, you will need [PHPUnit](https://phpunit.de/).
47+
| Command | Type |
48+
| ---------------- |:---------------:|
49+
| `composer test` | PHPUnit tests |
50+
| `composer style` | CodeSniffer |
51+
| `composer md` | MessDetector |
52+
| `composer check` | PHPStan |
3653

37-
### Contributing
54+
## Contributing
3855

3956
* File issues at https://github.com/designcise/bitframe-fastroute/issues
4057
* Issue patches to https://github.com/designcise/bitframe-fastroute/pulls
4158

42-
### Documentation
43-
44-
Documentation is available at:
59+
## Documentation
4560

46-
* https://www.bitframephp.com/middleware/router/fastroute/
61+
Complete documentation for v2.0 will be available soon.
4762

48-
### License
63+
## License
4964

5065
Please see [License File](LICENSE.md) for licensing information.

composer.json

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "designcise/bitframe-fastroute",
3-
"version": "1.0.4",
3+
"version": "2.0.0",
44
"type": "library",
55
"description": "FastRoute router middleware for BitFrame microframework",
66
"license": "MIT",
@@ -11,22 +11,34 @@
1111
}
1212
],
1313
"require": {
14-
"php": ">=7.1.0",
15-
"designcise/bitframe": "^1.0",
14+
"php": ">=7.4.0",
1615
"psr/http-server-middleware": "~1.0",
17-
"nikic/fast-route": "^1.3"
16+
"designcise/bitframe": "2.x-dev"
1817
},
1918
"require-dev": {
20-
"phpunit/phpunit": "^6.4"
19+
"phpunit/phpunit": "^8.5",
20+
"phpspec/prophecy": "~1.0",
21+
"squizlabs/php_codesniffer": "3.*",
22+
"phpmd/phpmd": "@stable",
23+
"phpstan/phpstan": "*"
2124
},
2225
"autoload": {
2326
"psr-4": {
24-
"BitFrame\\Router\\": "src/"
27+
"BitFrame\\FastRoute\\": "src/"
2528
}
2629
},
2730
"autoload-dev": {
2831
"psr-4": {
29-
"BitFrame\\Test\\": "test/"
32+
"BitFrame\\FastRoute\\Test\\": "test/"
3033
}
34+
},
35+
"config": {
36+
"sort-packages": true
37+
},
38+
"scripts": {
39+
"style": "vendor/bin/phpcs --standard=PSR12 src",
40+
"check": "vendor/bin/phpstan analyse src --level=5 -c phpstan.neon",
41+
"md": "vendor/bin/phpmd src text cleancode,unusedcode,codesize,design,naming",
42+
"test": "vendor/bin/phpunit --configuration phpunit.xml --testsuite bitframe_fastroute"
3143
}
3244
}

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

phpunit.xml

100644100755
Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,25 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22

3-
<phpunit bootstrap="vendor/autoload.php"
4-
backupGlobals="false"
3+
<phpunit backupGlobals="false"
54
backupStaticAttributes="false"
65
colors="true"
76
convertErrorsToExceptions="true"
87
convertNoticesToExceptions="true"
98
convertWarningsToExceptions="true"
109
processIsolation="false"
11-
syntaxCheck="false"
12-
>
10+
>
1311
<testsuites>
14-
<testsuite name="BitFrame Tests">
15-
<directory>./test/</directory>
12+
<testsuite name="bitframe_fastroute">
13+
<directory suffix="Test.php">./test</directory>
1614
</testsuite>
1715
</testsuites>
1816

1917
<filter>
2018
<whitelist>
21-
<directory>./src/</directory>
19+
<directory suffix=".php">./src/</directory>
20+
<exclude>
21+
<directory suffix=".php">./src/Exception</directory>
22+
</exclude>
2223
</whitelist>
2324
</filter>
2425
</phpunit>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
/**
4+
* BitFrame Framework (https://www.bitframephp.com)
5+
*
6+
* @author Daniyal Hamid
7+
* @copyright Copyright (c) 2017-2020 Daniyal Hamid (https://designcise.com)
8+
* @license https://bitframephp.com/about/license MIT License
9+
*/
10+
11+
declare(strict_types=1);
12+
13+
namespace BitFrame\FastRoute\Exception;
14+
15+
use LogicException;
16+
17+
class BadRouteException extends LogicException
18+
{
19+
}

src/Exception/HttpException.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
/**
4+
* BitFrame Framework (https://www.bitframephp.com)
5+
*
6+
* @author Daniyal Hamid
7+
* @copyright Copyright (c) 2017-2020 Daniyal Hamid (https://designcise.com)
8+
* @license https://bitframephp.com/about/license MIT License
9+
*/
10+
11+
declare(strict_types=1);
12+
13+
namespace BitFrame\FastRoute\Exception;
14+
15+
use RuntimeException;
16+
17+
use function http_response_code;
18+
19+
/**
20+
* Represents an HTTP error.
21+
*/
22+
class HttpException extends RuntimeException
23+
{
24+
public function __construct(string $message, int $statusCode = 500)
25+
{
26+
http_response_code($statusCode);
27+
parent::__construct($message, $statusCode);
28+
}
29+
}

0 commit comments

Comments
 (0)