Skip to content

Commit

Permalink
Merge pull request #309 from clue-labs/template-types
Browse files Browse the repository at this point in the history
Use Promise v3 template types
  • Loading branch information
WyriHaximus authored Aug 7, 2023
2 parents 5603979 + fd252bd commit 41580db
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 5 deletions.
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

0 comments on commit 41580db

Please sign in to comment.