Skip to content
This repository was archived by the owner on Sep 20, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .State

This file was deleted.

29 changes: 6 additions & 23 deletions Connection.php → Source/Connection.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/**
* Hoa
*
Expand Down Expand Up @@ -43,9 +45,6 @@
* Specification can be found here:
* http://fastcgi.com/devkit/doc/fcgi-spec.html.
* Inspired by PHP SAPI code: php://sapi/cgi/fastcgi.*.
*
* @copyright Copyright © 2007-2017 Hoa community
* @license New BSD License
*/
abstract class Connection
{
Expand Down Expand Up @@ -102,13 +101,8 @@ abstract class Connection

/**
* Pack data to a packet.
*
* @param int $type Packet's type.
* @param string $content Content.
* @param id $id Packet's ID.
* @return string
*/
public function pack($type, $content, $id = 1)
public function pack(int $type, string $content, int $id = 1): string
{
$length = strlen($content);

Expand All @@ -126,11 +120,8 @@ public function pack($type, $content, $id = 1)

/**
* Pack pairs (key/value).
*
* @param array $pairs Keys/values array.
* @return string
*/
public function packPairs(array $pairs)
public function packPairs(array $pairs): ?string
{
$out = null;

Expand Down Expand Up @@ -160,11 +151,8 @@ public function packPairs(array $pairs)

/**
* Unpack pairs (key/value).
*
* @param string $pack Packet to unpack.
* @return string
*/
public function unpackPairs($pack)
public function unpackPairs(string $pack): array
{
if (null === $length) {
$length = strlen($pack);
Expand Down Expand Up @@ -203,8 +191,6 @@ public function unpackPairs($pack)

/**
* Read a packet.
*
* @return array
*/
protected function readPack()
{
Expand Down Expand Up @@ -243,9 +229,6 @@ protected function readPack()

/**
* Read data.
*
* @param int $length Length of data to read.
* @return string
*/
abstract protected function read($length);
abstract protected function read(int $length): string;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/**
* Hoa
*
Expand Down Expand Up @@ -39,13 +41,10 @@
/**
* Class \Hoa\Fastcgi\Exception\CannotMultiplex.
*
* Extending the \Hoa\Fastcgi\Exception class.
* Extending the `Hoa\Fastcgi\Exception` class.
* This happens when a Web server sends concurrent requests over one connection
* to an application that is designed to process one request at a time per
* connection.
*
* @copyright Copyright © 2007-2017 Hoa community
* @license New BSD License
*/
class CannotMultiplex extends Exception
{
Expand Down
9 changes: 4 additions & 5 deletions Exception/Exception.php → Source/Exception/Exception.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/**
* Hoa
*
Expand Down Expand Up @@ -42,10 +44,7 @@
/**
* Class \Hoa\Fastcgi\Exception.
*
* Extending the \Hoa\Exception\Exception class.
*
* @copyright Copyright © 2007-2017 Hoa community
* @license New BSD License
* Extending the `Hoa\Exception\Exception` class.
*/
class Exception extends HoaException
{
Expand All @@ -54,4 +53,4 @@ class Exception extends HoaException
/**
* Flex entity.
*/
Consistency::flexEntity('Hoa\Fastcgi\Exception\Exception');
Consistency::flexEntity(Exception::class);
7 changes: 3 additions & 4 deletions Exception/Overloaded.php → Source/Exception/Overloaded.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/**
* Hoa
*
Expand Down Expand Up @@ -39,12 +41,9 @@
/**
* Class \Hoa\Fastcgi\Exception\Overloaded.
*
* Extending the \Hoa\Fastcgi\Exception class.
* Extending the `Hoa\Fastcgi\Exception` class.
* This happens when the application runs out of some resource, e.g. database
* connections.
*
* @copyright Copyright © 2007-2017 Hoa community
* @license New BSD License
*/
class Overloaded extends Exception
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/**
* Hoa
*
Expand Down Expand Up @@ -39,12 +41,9 @@
/**
* Class \Hoa\Fastcgi\Exception\UnknownRole.
*
* Extending the \Hoa\Fastcgi\Exception class.
* Extending the `Hoa\Fastcgi\Exception` class.
* This happens when the Web server has specified a role that is unknown to the
* application.
*
* @copyright Copyright © 2007-2017 Hoa community
* @license New BSD License
*/
class UnknownRole extends Exception
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/**
* Hoa
*
Expand Down Expand Up @@ -39,11 +41,8 @@
/**
* Class \Hoa\Fastcgi\Exception\UnknownStatus.
*
* Extending the \Hoa\Fastcgi\Exception class.
* Extending the `Hoa\Fastcgi\Exception` class.
* This happens when the response has an unknown status.
*
* @copyright Copyright © 2007-2017 Hoa community
* @license New BSD License
*/
class UnknownStatus extends Exception
{
Expand Down
51 changes: 12 additions & 39 deletions Responder.php → Source/Responder.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/**
* Hoa
*
Expand Down Expand Up @@ -43,9 +45,6 @@
*
* A FastCGI client with a responder role.
* Inspired by PHP SAPI code: php://sapi/cgi/fastcgi.*.
*
* @copyright Copyright © 2007-2017 Hoa community
* @license New BSD License
*/
class Responder extends Connection
{
Expand Down Expand Up @@ -133,21 +132,21 @@ class Responder extends Connection
/**
* Client socket connection.
*
* @var \Hoa\Socket\Client
* @var ?Socket\Client
*/
protected $_client = null;

/**
* Response's output.
*
* @var string
* @var ?string
*/
protected $_responseOutput = null;

/**
* Response's error.
*
* @var string
* @var ?string
*/
protected $_responseError = null;

Expand All @@ -162,8 +161,6 @@ class Responder extends Connection

/**
* Constructor.
*
* @param \Hoa\Socket\Client $client Client connection.
*/
public function __construct(Socket\Client $client)
{
Expand All @@ -174,18 +171,8 @@ public function __construct(Socket\Client $client)

/**
* Send data on a FastCGI.
*
* @param array $headers Headers.
* @param string $content Content (e.g. key=value for POST).
* @return string
* @throws \Hoa\Socket\Exception
* @throws \Hoa\Fastcgi\Exception
* @throws \Hoa\Fastcgi\Exception\CannotMultiplex
* @throws \Hoa\Fastcgi\Exception\Overloaded
* @throws \Hoa\Fastcgi\Exception\UnknownRole
* @throws \Hoa\Fastcgi\Exception\UnknownStatus
*/
public function send(array $headers, $content = null)
public function send(array $headers, ?string $content = null): string
{
$this->_responseOutput = null;
$this->_responseError = null;
Expand Down Expand Up @@ -304,52 +291,40 @@ public function send(array $headers, $content = null)

/**
* Get response content.
*
* @return ?string
*/
public function getResponseContent()
public function getResponseContent(): ?string
{
return $this->_responseOutput;
}

/**
* Get response error if any.
*
* @return ?string
*/
public function getResponseError()
public function getResponseError(): ?string
{
return $this->_responseError;
}

/**
* Get response headers.
*
* @return array
*/
public function getResponseHeaders()
public function getResponseHeaders(): array
{
return $this->_responseHeaders;
}

/**
* Read data.
*
* @param int $length Length of data to read.
* @return string
*/
protected function read($length)
protected function read(int $length): ?string
{
return $this->getClient()->read($length);
}

/**
* Set client.
*
* @param \Hoa\Socket\Client $client Client.
* @return \Hoa\Socket\Client
*/
public function setClient(Socket\Client $client)
public function setClient(Socket\Client $client): ?Socket\Client
{
$old = $this->_client;
$this->_client = $client;
Expand All @@ -359,10 +334,8 @@ public function setClient(Socket\Client $client)

/**
* Get client.
*
* @return \Hoa\Socket\Client
*/
public function getClient()
public function getClient(): Socket\Client
{
return $this->_client;
}
Expand Down
11 changes: 6 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,17 @@
"source": "https://central.hoa-project.net/Resource/Library/Fastcgi"
},
"require": {
"hoa/consistency": "~1.0",
"hoa/exception" : "~1.0",
"hoa/socket" : "~1.0"
"php" : ">=7.1",
"hoa/consistency": "dev-master",
"hoa/exception" : "dev-master",
"hoa/socket" : "dev-master"
},
"require-dev": {
"hoa/test": "~2.0"
"hoa/test": "dev-master"
},
"autoload": {
"psr-4": {
"Hoa\\Fastcgi\\": "."
"Hoa\\Fastcgi\\": "Source"
}
},
"extra": {
Expand Down