Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Promise v3 template types #309

Merged
merged 1 commit into from
Aug 7, 2023
Merged
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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -860,8 +860,8 @@ The interface only offers a single method:

#### connect()

The `connect(string $uri): PromiseInterface<ConnectionInterface,Exception>` method
can be used to create a streaming connection to the given remote address.
The `connect(string $uri): PromiseInterface<ConnectionInterface>` method can be used to
create a streaming connection to the given remote address.

It returns a [Promise](https://github.com/reactphp/promise) which either
fulfills with a stream implementing [`ConnectionInterface`](#connectioninterface)
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"phpunit/phpunit": "^9.5 || ^5.7 || ^4.8.35",
"react/async": "^4 || ^3 || ^2",
"react/promise-stream": "^1.4",
"react/promise-timer": "^1.9"
"react/promise-timer": "^1.10"
},
"autoload": {
"psr-4": {
Expand Down
3 changes: 2 additions & 1 deletion src/ConnectorInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ interface ConnectorInterface
* ```
*
* @param string $uri
* @return \React\Promise\PromiseInterface resolves with a stream implementing ConnectionInterface on success or rejects with an Exception on error
* @return \React\Promise\PromiseInterface<ConnectionInterface>
* Resolves with a `ConnectionInterface` on success or rejects with an `Exception` on error.
* @see ConnectionInterface
*/
public function connect($uri);
Expand Down
2 changes: 1 addition & 1 deletion src/SecureConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function connect($uri)
$context = $this->context;
$encryption = $this->streamEncryption;
$connected = false;
/** @var \React\Promise\PromiseInterface $promise */
/** @var \React\Promise\PromiseInterface<ConnectionInterface> $promise */
$promise = $this->connector->connect(
\str_replace('tls://', '', $uri)
)->then(function (ConnectionInterface $connection) use ($context, $encryption, $uri, &$promise, &$connected) {
Expand Down
17 changes: 17 additions & 0 deletions src/StreamEncryption.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,20 @@ public function __construct(LoopInterface $loop, $server = true)
}
}

/**
* @param Connection $stream
* @return \React\Promise\PromiseInterface<Connection>
*/
public function enable(Connection $stream)
{
return $this->toggle($stream, true);
}

/**
* @param Connection $stream
* @param bool $toggle
* @return \React\Promise\PromiseInterface<Connection>
*/
public function toggle(Connection $stream, $toggle)
{
// pause actual stream instance to continue operation on raw stream socket
Expand Down Expand Up @@ -98,6 +107,14 @@ public function toggle(Connection $stream, $toggle)
});
}

/**
* @internal
* @param resource $socket
* @param Deferred<null> $deferred
* @param bool $toggle
* @param int $method
* @return void
*/
public function toggleCrypto($socket, Deferred $deferred, $toggle, $method)
{
$error = null;
Expand Down