diff options
author | Wolfy-J <[email protected]> | 2018-06-04 16:44:37 +0300 |
---|---|---|
committer | Wolfy-J <[email protected]> | 2018-06-04 16:44:37 +0300 |
commit | 3c86132f90ef6473b4073a8b1500d01b6114fc30 (patch) | |
tree | 7e5b497c56b53f95df7085203554a5d33ec80afc | |
parent | e2996bcb8ef7409db7cfd54cb378dd260002e00f (diff) |
psr7 client
-rw-r--r-- | cmd/rr/.rr.yaml | 6 | ||||
-rw-r--r-- | php-src/PSR7Client.php (renamed from php-src/PSR7Worker.php) | 51 |
2 files changed, 36 insertions, 21 deletions
diff --git a/cmd/rr/.rr.yaml b/cmd/rr/.rr.yaml index aaabe7c2..2717e187 100644 --- a/cmd/rr/.rr.yaml +++ b/cmd/rr/.rr.yaml @@ -23,7 +23,7 @@ http: serve: true # root directory for static file (http would not serve .php and .htacess files). - root: "c:/goproj/phpapp/webroot" + root: "/Users/wolfy-j/Projects/phpapp/webroot" # file upload configuration. uploads: @@ -37,7 +37,7 @@ http: # http worker pool configuration. pool: # php worker command. - command: "php c:/goproj/phpapp/webroot/index.php rr pipes --no-ansi" + command: "php /Users/wolfy-j/Projects/phpapp/webroot/index.php rr pipes --no-ansi" # connection method (pipes, tcp://:9000, unix://socket.unix). relay: "pipes" @@ -46,7 +46,7 @@ http: number: 1 # maximum jobs per worker, 0 - unlimited. - maxJobs: 1 + maxJobs: 0 # worker allocation timeouts. timeouts: diff --git a/php-src/PSR7Worker.php b/php-src/PSR7Client.php index 65225d85..0f618d9e 100644 --- a/php-src/PSR7Worker.php +++ b/php-src/PSR7Client.php @@ -5,35 +5,47 @@ * @author Wolfy-J */ +namespace Spiral\RoadRunner; + +use Psr\Http\Message\ResponseInterface; +use Psr\Http\Message\ServerRequestInterface; +use Spiral\RoadRunner\Worker; +use Zend\Diactoros\ServerRequest; +use Zend\Diactoros\Stream; +use Zend\Diactoros\UploadedFile; /** - * Class PSR7Worker serves PSR-7 requests and consume responses. + * Spiral Framework, SpiralScout LLC. + * + * @package spiralFramework + * @author Anton Titov (Wolfy-J) + * @copyright ©2009-2011 */ -class PSR7Worker +class PSR7Client { /** - * @var \Spiral\RoadRunner\Worker + * @varWorker */ private $worker; /** - * @param \Spiral\RoadRunner\Worker $worker + * @param Worker $worker */ - public function __construct(\Spiral\RoadRunner\Worker $worker) + public function __construct(Worker $worker) { $this->worker = $worker; } /** - * @return \Spiral\RoadRunner\Worker + * @return Worker */ - public function getWorker(): \Spiral\RoadRunner\Worker + public function getWorker(): Worker { return $this->worker; } /** - * @return \Psr\Http\Message\ServerRequestInterface|null + * @return ServerRequestInterface|null */ public function acceptRequest() { @@ -43,23 +55,28 @@ class PSR7Worker return null; } + if (empty($ctx = json_decode($ctx, true))) { + // invalid context + return null; + } + parse_str($ctx['rawQuery'], $query); - $body = 'php://input'; + $bodyStream = 'php://input'; $parsedBody = null; if ($ctx['parsed']) { $parsedBody = json_decode($body, true); } elseif ($body != null) { - $parsedBody = new \Zend\Diactoros\Stream("php://memory", "rwb"); - $parsedBody->write($body); + $bodyStream = new Stream("php://memory", "rwb"); + $bodyStream->write($body); } - return new \Zend\Diactoros\ServerRequest( + return new ServerRequest( $_SERVER, $this->wrapUploads($ctx['uploads']), $ctx['uri'], $ctx['method'], - $body, + $bodyStream, $ctx['headers'], $ctx['cookies'], $query, @@ -71,12 +88,10 @@ class PSR7Worker /** * Send response to the application server. * - * @param \Psr\Http\Message\ResponseInterface $response + * @param ResponseInterface $response */ - public function respond(\Psr\Http\Message\ResponseInterface $response) + public function respond(ResponseInterface $response) { - $this->worker->error("asd"); - $this->worker->send($response->getBody(), json_encode([ 'status' => $response->getStatusCode(), 'headers' => $response->getHeaders() @@ -99,7 +114,7 @@ class PSR7Worker $result = []; foreach ($files as $index => $file) { if (isset($file['name'])) { - $result[$index] = new \Zend\Diactoros\UploadedFile( + $result[$index] = new UploadedFile( $file['tmpName'], $file['size'], $file['error'], |