Skip to content

Commit 40d6662

Browse files
committed
zend factory dependency elliminated
1 parent d890e97 commit 40d6662

11 files changed

+122
-13
lines changed

composer.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@
1111
],
1212
"require": {
1313
"php": "^7.0",
14+
"ext-json": "*",
1415
"spiral/goridge": "^2.0",
1516
"psr/http-factory": "^1.0",
1617
"psr/http-message": "^1.0",
17-
"http-interop/http-factory-diactoros": "^1.0"
18+
"zendframework/zend-diactoros": "^1.3|^2.0"
1819
},
1920
"autoload": {
2021
"psr-4": {

go.mod

+2-5
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,15 @@ require (
1313
github.com/mattn/go-isatty v0.0.4 // indirect
1414
github.com/mattn/go-runewidth v0.0.3 // indirect
1515
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b
16-
github.com/mitchellh/mapstructure v1.1.2 // indirect
1716
github.com/olekukonko/tablewriter v0.0.0-20180912035003-be2c049b30cc
1817
github.com/pkg/errors v0.8.0
1918
github.com/shirou/gopsutil v2.17.12+incompatible
2019
github.com/shirou/w32 v0.0.0-20160930032740-bb4de0191aa4 // indirect
2120
github.com/sirupsen/logrus v1.1.1
2221
github.com/spf13/cobra v0.0.3
23-
github.com/spf13/pflag v1.0.3 // indirect
24-
github.com/spf13/viper v1.2.1
22+
github.com/spf13/viper v1.3.1
2523
github.com/spiral/goridge v2.1.3+incompatible
26-
golang.org/x/crypto v0.0.0-20181015023909-0c41d7ab0a0e // indirect
24+
github.com/stretchr/testify v1.2.2
2725
golang.org/x/net v0.0.0-20181017193950-04a2e542c03f
28-
golang.org/x/sys v0.0.0-20181011152604-fa43e7bc11ba // indirect
2926
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect
3027
)
File renamed without changes.
File renamed without changes.
+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
/**
5+
* High-performance PHP process supervisor and load balancer written in Go
6+
*
7+
* @author Wolfy-J
8+
*/
9+
10+
namespace Spiral\RoadRunner\Diactoros;
11+
12+
use Psr\Http\Message\ServerRequestFactoryInterface;
13+
use Psr\Http\Message\ServerRequestInterface;
14+
use Zend\Diactoros\ServerRequest;
15+
16+
final class ServerRequestFactory implements ServerRequestFactoryInterface
17+
{
18+
/**
19+
* @inheritdoc
20+
*/
21+
public function createServerRequest(string $method, $uri, array $serverParams = []): ServerRequestInterface
22+
{
23+
$uploadedFiles = [];
24+
return new ServerRequest($serverParams, $uploadedFiles, $uri, $method);
25+
}
26+
}

src/Diactoros/StreamFactory.php

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
/**
5+
* High-performance PHP process supervisor and load balancer written in Go
6+
*
7+
* @author Wolfy-J
8+
*/
9+
10+
namespace Spiral\RoadRunner\Diactoros;
11+
12+
use Psr\Http\Message\StreamFactoryInterface;
13+
use Psr\Http\Message\StreamInterface;
14+
use Zend\Diactoros\Stream;
15+
16+
final class StreamFactory implements StreamFactoryInterface
17+
{
18+
/**
19+
* @inheritdoc
20+
*/
21+
public function createStream(string $content = ''): StreamInterface
22+
{
23+
$resource = fopen('php://temp', 'r+');
24+
fwrite($resource, $content);
25+
rewind($resource);
26+
return $this->createStreamFromResource($resource);
27+
}
28+
29+
/**
30+
* @inheritdoc
31+
*/
32+
public function createStreamFromFile(string $file, string $mode = 'r'): StreamInterface
33+
{
34+
$resource = fopen($file, $mode);
35+
return $this->createStreamFromResource($resource);
36+
}
37+
38+
/**
39+
* @inheritdoc
40+
*/
41+
public function createStreamFromResource($resource): StreamInterface
42+
{
43+
return new Stream($resource);
44+
}
45+
}

src/Diactoros/UploadedFileFactory.php

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
/**
5+
* High-performance PHP process supervisor and load balancer written in Go
6+
*
7+
* @author Wolfy-J
8+
*/
9+
10+
namespace Spiral\RoadRunner\Diactoros;
11+
12+
use Psr\Http\Message\StreamInterface;
13+
use Psr\Http\Message\UploadedFileFactoryInterface;
14+
use Psr\Http\Message\UploadedFileInterface;
15+
use Zend\Diactoros\UploadedFile;
16+
17+
final class UploadedFileFactory implements UploadedFileFactoryInterface
18+
{
19+
/**
20+
* @inheritdoc
21+
*/
22+
public function createUploadedFile(
23+
StreamInterface $stream,
24+
int $size = null,
25+
int $error = \UPLOAD_ERR_OK,
26+
string $clientFilename = null,
27+
string $clientMediaType = null
28+
): UploadedFileInterface {
29+
if ($size === null) {
30+
$size = $stream->getSize();
31+
}
32+
33+
return new UploadedFile($stream, $size, $error, $clientFilename, $clientMediaType);
34+
}
35+
}

src/Exception/RoadRunnerException.php

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<?php
2+
declare(strict_types=1);
3+
24
/**
35
* High-performance PHP process supervisor and load balancer written in Go
46
*

src/PSR7Client.php

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<?php
2+
declare(strict_types=1);
3+
24
/**
35
* High-performance PHP process supervisor and load balancer written in Go
46
*
@@ -7,7 +9,6 @@
79

810
namespace Spiral\RoadRunner;
911

10-
use Http\Factory\Diactoros;
1112
use Psr\Http\Message\ResponseInterface;
1213
use Psr\Http\Message\ServerRequestFactoryInterface;
1314
use Psr\Http\Message\ServerRequestInterface;
@@ -124,10 +125,10 @@ public function respond(ResponseInterface $response)
124125
$headers = new \stdClass();
125126
}
126127

127-
$this->worker->send($response->getBody(), json_encode([
128-
'status' => $response->getStatusCode(),
129-
'headers' => $headers
130-
]));
128+
$this->worker->send(
129+
$response->getBody()->__toString(),
130+
json_encode(['status' => $response->getStatusCode(), 'headers' => $headers])
131+
);
131132
}
132133

133134
/**

src/Worker.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<?php
2+
declare(strict_types=1);
3+
24
/**
35
* High-performance PHP process supervisor and load balancer written in Go
46
*
@@ -132,7 +134,7 @@ public function stop()
132134
*
133135
* @throws RoadRunnerException
134136
*/
135-
private function handleControl(string $body = null, &$header = null, int $flags): bool
137+
private function handleControl(string $body = null, &$header = null, int $flags = 0): bool
136138
{
137139
$header = $body;
138140
if (is_null($body) || $flags & Relay::PAYLOAD_RAW) {

tests/http/pid.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
function handleRequest(ServerRequestInterface $req, ResponseInterface $resp): ResponseInterface
77
{
8-
$resp->getBody()->write(getmypid());
8+
$resp->getBody()->write((string)getmypid());
99

1010
return $resp;
1111
}

0 commit comments

Comments
 (0)