Skip to content

Commit 0cf97f9

Browse files
committed
Initial commit
1 parent 8221ca2 commit 0cf97f9

15 files changed

+1358
-410
lines changed

.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

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-2019 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: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,54 @@
1-
# BitFrame\Router\FastRouteRouter
1+
# BitFrame\FastRoute
22

33
FastRoute wrapper class to manage http routes as a middleware.
44

5-
### Installation
5+
## Installation
66

7-
See [installation docs](https://www.bitframephp.com/middleware/router/fastroute) for instructions on installing and using this middleware.
7+
Install using composer:
88

9-
### Usage Example
9+
```
10+
$ composer require designcise/bitframe-fastroute
11+
```
12+
13+
Please note that this package requires PHP 7.4.0 or newer.
14+
15+
## Usage Example
1016

1117
```
12-
use \BitFrame\Router\FastRouteRouter;
18+
use BitFrame\App;
19+
use BitFrame\Emitter\SapiEmitter;
20+
use BitFrame\FastRoute\Router;
1321
1422
require 'vendor/autoload.php';
1523
16-
$app = new \BitFrame\Application;
24+
$app = new App();
25+
$router = new Router();
1726
18-
$app->map(['GET', 'POST'], '/test', function ($request, $response, $next) {
19-
$response->getBody()->write('Test Page');
20-
21-
return $response;
27+
$router->map(['GET', 'POST'], '/test', function ($request, $handler) {
28+
$handler->write('Test Page');
29+
return $handler->handle($request);
2230
});
2331
2432
$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
33+
SapiEmitter::class,
34+
$router,
35+
// ...
3036
]);
3137
```
3238

33-
### Tests
39+
## Tests
3440

3541
To execute the test suite, you will need [PHPUnit](https://phpunit.de/).
3642

37-
### Contributing
43+
## Contributing
3844

3945
* File issues at https://github.com/designcise/bitframe-fastroute/issues
4046
* Issue patches to https://github.com/designcise/bitframe-fastroute/pulls
4147

42-
### Documentation
43-
44-
Documentation is available at:
48+
## Documentation
4549

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

48-
### License
52+
## License
4953

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

composer.json

Lines changed: 15 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,30 @@
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+
"squizlabs/php_codesniffer": "3.*",
21+
"phpmd/phpmd": "@stable"
2122
},
2223
"autoload": {
2324
"psr-4": {
24-
"BitFrame\\Router\\": "src/"
25+
"BitFrame\\FastRoute\\": "src/"
2526
}
2627
},
2728
"autoload-dev": {
2829
"psr-4": {
29-
"BitFrame\\Test\\": "test/"
30+
"BitFrame\\FastRoute\\Test\\": "test/"
3031
}
32+
},
33+
"config": {
34+
"sort-packages": true
35+
},
36+
"scripts": {
37+
"style": "vendor/bin/phpcs --standard=PSR12 src",
38+
"test": "vendor/bin/phpunit --configuration phpunit.xml --testsuite unit"
3139
}
3240
}

phpunit.xml

100644100755
Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
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="unit">
13+
<directory suffix="Test.php">./test</directory>
1614
</testsuite>
1715
</testsuites>
1816

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
/**
4+
* BitFrame Framework (https://www.bitframephp.com)
5+
*
6+
* @author Daniyal Hamid
7+
* @copyright Copyright (c) 2017-2019 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+
class BadRouteException extends \LogicException
16+
{
17+
}

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-2019 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+
/**
16+
* Represents an HTTP error.
17+
*/
18+
class HttpException extends \RuntimeException
19+
{
20+
/**
21+
* @param string $message
22+
* @param int $code Status code
23+
*/
24+
public function __construct(string $message, int $code = 500)
25+
{
26+
http_response_code($code);
27+
parent::__construct($message, $code);
28+
}
29+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
/**
4+
* BitFrame Framework (https://www.bitframephp.com)
5+
*
6+
* @author Daniyal Hamid
7+
* @copyright Copyright (c) 2017-2019 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+
/**
16+
* Represents an HTTP 405 error.
17+
*/
18+
class MethodNotAllowedException extends HttpException
19+
{
20+
/**
21+
* @param string $method Name of the method
22+
*/
23+
public function __construct(string $method)
24+
{
25+
parent::__construct(\sprintf('Method "%s" Not Allowed', $method), 405);
26+
}
27+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
/**
4+
* BitFrame Framework (https://www.bitframephp.com)
5+
*
6+
* @author Daniyal Hamid
7+
* @copyright Copyright (c) 2017-2019 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+
/**
16+
* Represents a route not found error.
17+
*/
18+
class RouteNotFoundException extends HttpException
19+
{
20+
/**
21+
* @param string $type
22+
*/
23+
public function __construct(string $type)
24+
{
25+
parent::__construct(\sprintf('Route "%s" cannot be found', $type), 404);
26+
}
27+
}

0 commit comments

Comments
 (0)