Skip to content

Commit 2cd374e

Browse files
committed
replace psr middleware interface. some update
1 parent d702787 commit 2cd374e

File tree

9 files changed

+25
-79
lines changed

9 files changed

+25
-79
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
}
1414
],
1515
"require": {
16-
"php": ">=7.0.0",
16+
"php": ">7.0.0",
1717
"psr/http-server-middleware": "^1.0"
1818
},
1919
"autoload": {

examples/app.php renamed to example/app.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
*/
88

99
use Inhere\Http\HttpFactory;
10-
use Inhere\Library\Helpers\Http;
10+
use Inhere\Http\HttpUtil;
1111
use Inhere\Middleware\MiddlewareStackAwareTrait;
12-
use Inhere\Middleware\RequestHandlerInterface;
12+
use Psr\Http\Server\RequestHandlerInterface;
1313
use Inhere\Route\ORouter;
14-
use Inhere\Route\RouterInterface;
14+
use Inhere\Route\Base\RouterInterface;
1515
use Psr\Http\Message\ResponseInterface;
1616
use Psr\Http\Message\ServerRequestInterface;
1717

@@ -29,7 +29,7 @@ public function run(ServerRequestInterface $request)
2929
{
3030
$response = $this->callStack($request);
3131

32-
Http::respond($response);
32+
HttpUtil::respond($response);
3333
}
3434

3535
/**

examples/test.php renamed to example/test.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,10 @@
66
* Time: 下午10:04
77
*/
88

9-
use Inhere\Http\Body;
109
use Inhere\Http\HttpFactory;
1110
use Inhere\Middleware\MiddlewareStack;
12-
use Inhere\Middleware\RequestHandlerInterface;
1311
use Psr\Http\Message\ServerRequestInterface;
12+
use Psr\Http\Server\RequestHandlerInterface;
1413

1514
require dirname(__DIR__) . '/../../autoload.php';
1615

@@ -39,25 +38,28 @@ function (ServerRequestInterface $request, RequestHandlerInterface $handler) {
3938
$res = $handler->handle($request);
4039
$res->getBody()->write(' + node 1');
4140
echo "1 after >>> \n";
41+
4242
return $res;
4343
},
4444
function (ServerRequestInterface $request, RequestHandlerInterface $handler) {
4545
echo ">>> 2 before \n";
4646
$res = $handler->handle($request);
4747
$res->getBody()->write(' + node 2');
4848
echo "2 after >>> \n";
49+
4950
return $res;
5051
},
5152
function (ServerRequestInterface $request, RequestHandlerInterface $handler) {
5253
echo ">>> 3 before \n";
5354
$res = $handler->handle($request);
5455
$res->getBody()->write(' + node 3');
5556
echo "3 after >>> \n";
57+
5658
return $res;
5759
},
5860
function (ServerRequestInterface $request, RequestHandlerInterface $handler) {
59-
// $res = HttpFactory::createResponse();
60-
// $res->getBody()->write('content');
61+
// $res = HttpFactory::createResponse();
62+
// $res->getBody()->write('content');
6163

6264
echo ">>> 4 before \n";
6365
$res = $handler->handle($request);
@@ -71,10 +73,12 @@ function (ServerRequestInterface $request, RequestHandlerInterface $handler) {
7173

7274
$request = HttpFactory::createServerRequest('GET', 'http://www.abc.com/home');
7375

74-
$chain->setCoreHandler(function (ServerRequestInterface $request) {
76+
$chain->setCoreHandler(function () {
7577
echo " (this is core)\n";
78+
$res = HttpFactory::createResponse();
79+
$res->getBody()->write('-CORE-');
7680

77-
return HttpFactory::createResponse()->write('-CORE-');
81+
return $res;
7882
});
7983

8084
$res = $chain($request);

phpunit.xml.dist

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<phpunit backupGlobals="false"
44
backupStaticAttributes="false"
5-
bootstrap="./tests/boot.php"
5+
bootstrap="test/boot.php"
66
colors="false"
77
convertErrorsToExceptions="true"
88
convertNoticesToExceptions="true"
@@ -12,13 +12,13 @@
1212
>
1313
<testsuites>
1414
<testsuite name="Inhere Middleware Test Suite">
15-
<directory>./tests/</directory>
15+
<directory>test</directory>
1616
</testsuite>
1717
</testsuites>
1818

1919
<filter>
2020
<whitelist>
21-
<directory suffix=".php">./examples</directory>
21+
<directory suffix=".php">src</directory>
2222
</whitelist>
2323
</filter>
2424
</phpunit>

src/MiddlewareInterface.php

Lines changed: 0 additions & 35 deletions
This file was deleted.

src/MiddlewareStack.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
use Psr\Http\Message\ResponseInterface;
1212
use Psr\Http\Message\ServerRequestInterface;
13+
use Psr\Http\Server\MiddlewareInterface;
14+
use Psr\Http\Server\RequestHandlerInterface;
1315

1416
/**
1517
* Class MiddlewareChain

src/MiddlewareStackAwareTrait.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
use Psr\Http\Message\ResponseInterface;
1212
use Psr\Http\Message\ServerRequestInterface;
13+
use Psr\Http\Server\MiddlewareInterface;
14+
use Psr\Http\Server\RequestHandlerInterface;
1315

1416
/**
1517
* Trait MiddlewareChainAwareTrait
@@ -125,7 +127,9 @@ public function handle(ServerRequestInterface $request): ResponseInterface
125127
}
126128

127129
if (!$response instanceof ResponseInterface) {
128-
throw new \UnexpectedValueException('Middleware must return instance of \Psr\Http\Message\ResponseInterface');
130+
throw new \UnexpectedValueException(
131+
'Middleware must return object and instance of \Psr\Http\Message\ResponseInterface'
132+
);
129133
}
130134

131135
return $response;

src/RequestHandlerInterface.php

Lines changed: 0 additions & 29 deletions
This file was deleted.
File renamed without changes.

0 commit comments

Comments
 (0)