diff options
author | Wolfy-J <[email protected]> | 2019-01-05 16:13:00 +0300 |
---|---|---|
committer | Wolfy-J <[email protected]> | 2019-01-05 16:13:00 +0300 |
commit | 40d66629617f7a96b9005df356b94ab3b4dfb98f (patch) | |
tree | 9901e93d20d57affbdbc88963956c78586eb0b00 | |
parent | d890e973c45fbe53916304321f185ce940776bb7 (diff) |
zend factory dependency elliminated
-rw-r--r-- | composer.json | 3 | ||||
-rw-r--r-- | go.mod | 7 | ||||
-rw-r--r-- | osutil/isolate.go (renamed from osutil/cmd_group.go) | 0 | ||||
-rw-r--r-- | osutil/isolate_win.go (renamed from osutil/cmd_group_win.go) | 0 | ||||
-rw-r--r-- | src/Diactoros/ServerRequestFactory.php | 26 | ||||
-rw-r--r-- | src/Diactoros/StreamFactory.php | 45 | ||||
-rw-r--r-- | src/Diactoros/UploadedFileFactory.php | 35 | ||||
-rw-r--r-- | src/Exception/RoadRunnerException.php | 2 | ||||
-rw-r--r-- | src/PSR7Client.php | 11 | ||||
-rw-r--r-- | src/Worker.php | 4 | ||||
-rw-r--r-- | tests/http/pid.php | 2 |
11 files changed, 122 insertions, 13 deletions
diff --git a/composer.json b/composer.json index 591a1ae8..a811d756 100644 --- a/composer.json +++ b/composer.json @@ -11,10 +11,11 @@ ], "require": { "php": "^7.0", + "ext-json": "*", "spiral/goridge": "^2.0", "psr/http-factory": "^1.0", "psr/http-message": "^1.0", - "http-interop/http-factory-diactoros": "^1.0" + "zendframework/zend-diactoros": "^1.3|^2.0" }, "autoload": { "psr-4": { @@ -13,18 +13,15 @@ require ( github.com/mattn/go-isatty v0.0.4 // indirect github.com/mattn/go-runewidth v0.0.3 // indirect github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b - github.com/mitchellh/mapstructure v1.1.2 // indirect github.com/olekukonko/tablewriter v0.0.0-20180912035003-be2c049b30cc github.com/pkg/errors v0.8.0 github.com/shirou/gopsutil v2.17.12+incompatible github.com/shirou/w32 v0.0.0-20160930032740-bb4de0191aa4 // indirect github.com/sirupsen/logrus v1.1.1 github.com/spf13/cobra v0.0.3 - github.com/spf13/pflag v1.0.3 // indirect - github.com/spf13/viper v1.2.1 + github.com/spf13/viper v1.3.1 github.com/spiral/goridge v2.1.3+incompatible - golang.org/x/crypto v0.0.0-20181015023909-0c41d7ab0a0e // indirect + github.com/stretchr/testify v1.2.2 golang.org/x/net v0.0.0-20181017193950-04a2e542c03f - golang.org/x/sys v0.0.0-20181011152604-fa43e7bc11ba // indirect gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect ) diff --git a/osutil/cmd_group.go b/osutil/isolate.go index d4b64fb6..d4b64fb6 100644 --- a/osutil/cmd_group.go +++ b/osutil/isolate.go diff --git a/osutil/cmd_group_win.go b/osutil/isolate_win.go index ca7fca20..ca7fca20 100644 --- a/osutil/cmd_group_win.go +++ b/osutil/isolate_win.go diff --git a/src/Diactoros/ServerRequestFactory.php b/src/Diactoros/ServerRequestFactory.php new file mode 100644 index 00000000..4d427121 --- /dev/null +++ b/src/Diactoros/ServerRequestFactory.php @@ -0,0 +1,26 @@ +<?php +declare(strict_types=1); + +/** + * High-performance PHP process supervisor and load balancer written in Go + * + * @author Wolfy-J + */ + +namespace Spiral\RoadRunner\Diactoros; + +use Psr\Http\Message\ServerRequestFactoryInterface; +use Psr\Http\Message\ServerRequestInterface; +use Zend\Diactoros\ServerRequest; + +final class ServerRequestFactory implements ServerRequestFactoryInterface +{ + /** + * @inheritdoc + */ + public function createServerRequest(string $method, $uri, array $serverParams = []): ServerRequestInterface + { + $uploadedFiles = []; + return new ServerRequest($serverParams, $uploadedFiles, $uri, $method); + } +}
\ No newline at end of file diff --git a/src/Diactoros/StreamFactory.php b/src/Diactoros/StreamFactory.php new file mode 100644 index 00000000..6004ef11 --- /dev/null +++ b/src/Diactoros/StreamFactory.php @@ -0,0 +1,45 @@ +<?php +declare(strict_types=1); + +/** + * High-performance PHP process supervisor and load balancer written in Go + * + * @author Wolfy-J + */ + +namespace Spiral\RoadRunner\Diactoros; + +use Psr\Http\Message\StreamFactoryInterface; +use Psr\Http\Message\StreamInterface; +use Zend\Diactoros\Stream; + +final class StreamFactory implements StreamFactoryInterface +{ + /** + * @inheritdoc + */ + public function createStream(string $content = ''): StreamInterface + { + $resource = fopen('php://temp', 'r+'); + fwrite($resource, $content); + rewind($resource); + return $this->createStreamFromResource($resource); + } + + /** + * @inheritdoc + */ + public function createStreamFromFile(string $file, string $mode = 'r'): StreamInterface + { + $resource = fopen($file, $mode); + return $this->createStreamFromResource($resource); + } + + /** + * @inheritdoc + */ + public function createStreamFromResource($resource): StreamInterface + { + return new Stream($resource); + } +}
\ No newline at end of file diff --git a/src/Diactoros/UploadedFileFactory.php b/src/Diactoros/UploadedFileFactory.php new file mode 100644 index 00000000..1543a826 --- /dev/null +++ b/src/Diactoros/UploadedFileFactory.php @@ -0,0 +1,35 @@ +<?php +declare(strict_types=1); + +/** + * High-performance PHP process supervisor and load balancer written in Go + * + * @author Wolfy-J + */ + +namespace Spiral\RoadRunner\Diactoros; + +use Psr\Http\Message\StreamInterface; +use Psr\Http\Message\UploadedFileFactoryInterface; +use Psr\Http\Message\UploadedFileInterface; +use Zend\Diactoros\UploadedFile; + +final class UploadedFileFactory implements UploadedFileFactoryInterface +{ + /** + * @inheritdoc + */ + public function createUploadedFile( + StreamInterface $stream, + int $size = null, + int $error = \UPLOAD_ERR_OK, + string $clientFilename = null, + string $clientMediaType = null + ): UploadedFileInterface { + if ($size === null) { + $size = $stream->getSize(); + } + + return new UploadedFile($stream, $size, $error, $clientFilename, $clientMediaType); + } +}
\ No newline at end of file diff --git a/src/Exception/RoadRunnerException.php b/src/Exception/RoadRunnerException.php index ee99bb2b..7c5c5929 100644 --- a/src/Exception/RoadRunnerException.php +++ b/src/Exception/RoadRunnerException.php @@ -1,4 +1,6 @@ <?php +declare(strict_types=1); + /** * High-performance PHP process supervisor and load balancer written in Go * diff --git a/src/PSR7Client.php b/src/PSR7Client.php index 0b148884..1136ce10 100644 --- a/src/PSR7Client.php +++ b/src/PSR7Client.php @@ -1,4 +1,6 @@ <?php +declare(strict_types=1); + /** * High-performance PHP process supervisor and load balancer written in Go * @@ -7,7 +9,6 @@ namespace Spiral\RoadRunner; -use Http\Factory\Diactoros; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestFactoryInterface; use Psr\Http\Message\ServerRequestInterface; @@ -124,10 +125,10 @@ class PSR7Client $headers = new \stdClass(); } - $this->worker->send($response->getBody(), json_encode([ - 'status' => $response->getStatusCode(), - 'headers' => $headers - ])); + $this->worker->send( + $response->getBody()->__toString(), + json_encode(['status' => $response->getStatusCode(), 'headers' => $headers]) + ); } /** diff --git a/src/Worker.php b/src/Worker.php index 7f92a714..da80e461 100644 --- a/src/Worker.php +++ b/src/Worker.php @@ -1,4 +1,6 @@ <?php +declare(strict_types=1); + /** * High-performance PHP process supervisor and load balancer written in Go * @@ -132,7 +134,7 @@ class Worker * * @throws RoadRunnerException */ - private function handleControl(string $body = null, &$header = null, int $flags): bool + private function handleControl(string $body = null, &$header = null, int $flags = 0): bool { $header = $body; if (is_null($body) || $flags & Relay::PAYLOAD_RAW) { diff --git a/tests/http/pid.php b/tests/http/pid.php index 1cc322bf..0c9a4e4d 100644 --- a/tests/http/pid.php +++ b/tests/http/pid.php @@ -5,7 +5,7 @@ use Psr\Http\Message\ServerRequestInterface; function handleRequest(ServerRequestInterface $req, ResponseInterface $resp): ResponseInterface { - $resp->getBody()->write(getmypid()); + $resp->getBody()->write((string)getmypid()); return $resp; }
\ No newline at end of file |