diff --git a/src/danog/MadelineProto/Stream/ADNLTransport/ADNLStream.php b/src/danog/MadelineProto/Stream/ADNLTransport/ADNLStream.php index 81900e15..c068f186 100644 --- a/src/danog/MadelineProto/Stream/ADNLTransport/ADNLStream.php +++ b/src/danog/MadelineProto/Stream/ADNLTransport/ADNLStream.php @@ -46,9 +46,9 @@ class ADNLStream implements BufferedStreamInterface, MTProtoBufferInterface * * @return \Generator */ - public function connectGenerator(ConnectionContext $ctx, string $header = ''): \Generator + public function connect(ConnectionContext $ctx, string $header = ''): \Generator { - $this->stream = (yield $ctx->getStream($header)); + $this->stream = yield from $ctx->getStream($header); } /** * Async close. diff --git a/src/danog/MadelineProto/Stream/Async/BufferedStream.php b/src/danog/MadelineProto/Stream/Async/BufferedStream.php index 5cba6395..4aa87bc4 100644 --- a/src/danog/MadelineProto/Stream/Async/BufferedStream.php +++ b/src/danog/MadelineProto/Stream/Async/BufferedStream.php @@ -30,7 +30,6 @@ use Amp\Promise; */ trait BufferedStream { - use Stream; /** * Get read buffer asynchronously. * diff --git a/src/danog/MadelineProto/Stream/Async/RawStream.php b/src/danog/MadelineProto/Stream/Async/RawStream.php index 162943ff..24025ecf 100644 --- a/src/danog/MadelineProto/Stream/Async/RawStream.php +++ b/src/danog/MadelineProto/Stream/Async/RawStream.php @@ -30,7 +30,6 @@ use Amp\Promise; */ trait RawStream { - use Stream; public function read(): Promise { return \danog\MadelineProto\Tools::call($this->readGenerator()); diff --git a/src/danog/MadelineProto/Stream/Async/Stream.php b/src/danog/MadelineProto/Stream/Async/Stream.php deleted file mode 100644 index 590b79c8..00000000 --- a/src/danog/MadelineProto/Stream/Async/Stream.php +++ /dev/null @@ -1,38 +0,0 @@ -. - * - * @author Daniil Gentili - * @copyright 2016-2019 Daniil Gentili - * @license https://opensource.org/licenses/AGPL-3.0 AGPLv3 - * - * @link https://docs.madelineproto.xyz MadelineProto documentation - */ - -namespace danog\MadelineProto\Stream\Async; - -use Amp\Promise; -use danog\MadelineProto\Stream\ConnectionContext; - -/** - * Generic stream helper trait. - * - * Wraps the asynchronous generator methods with asynchronous promise-based methods - * - * @author Daniil Gentili - */ -trait Stream -{ - public function connect(ConnectionContext $ctx, string $header = ''): Promise - { - return \danog\MadelineProto\Tools::call($this->connectGenerator($ctx, $header)); - } -} diff --git a/src/danog/MadelineProto/Stream/Common/BufferedRawStream.php b/src/danog/MadelineProto/Stream/Common/BufferedRawStream.php index 69daaad4..3a767745 100644 --- a/src/danog/MadelineProto/Stream/Common/BufferedRawStream.php +++ b/src/danog/MadelineProto/Stream/Common/BufferedRawStream.php @@ -49,9 +49,9 @@ class BufferedRawStream implements BufferedStreamInterface, BufferInterface, Raw * * @return \Generator */ - public function connectGenerator(ConnectionContext $ctx, string $header = ''): \Generator + public function connect(ConnectionContext $ctx, string $header = ''): \Generator { - $this->stream = (yield $ctx->getStream($header)); + $this->stream = yield from $ctx->getStream($header); $this->memory_stream = \fopen('php://memory', 'r+'); return true; } diff --git a/src/danog/MadelineProto/Stream/Common/CtrStream.php b/src/danog/MadelineProto/Stream/Common/CtrStream.php index 4a71b508..07586eba 100644 --- a/src/danog/MadelineProto/Stream/Common/CtrStream.php +++ b/src/danog/MadelineProto/Stream/Common/CtrStream.php @@ -55,7 +55,7 @@ class CtrStream implements BufferedProxyStreamInterface, BufferInterface * * @return \Generator */ - public function connectGenerator(ConnectionContext $ctx, string $header = ''): \Generator + public function connect(ConnectionContext $ctx, string $header = ''): \Generator { $this->encrypt = new \tgseclib\Crypt\AES('ctr'); $this->encrypt->enableContinuousBuffer(); @@ -65,7 +65,7 @@ class CtrStream implements BufferedProxyStreamInterface, BufferInterface $this->decrypt->enableContinuousBuffer(); $this->decrypt->setKey($this->extra['decrypt']['key']); $this->decrypt->setIV($this->extra['decrypt']['iv']); - $this->stream = (yield $ctx->getStream($header)); + $this->stream = (yield from $ctx->getStream($header)); } /** * Async close. diff --git a/src/danog/MadelineProto/Stream/Common/HashedBufferedStream.php b/src/danog/MadelineProto/Stream/Common/HashedBufferedStream.php index 4efef873..26749a5c 100644 --- a/src/danog/MadelineProto/Stream/Common/HashedBufferedStream.php +++ b/src/danog/MadelineProto/Stream/Common/HashedBufferedStream.php @@ -189,7 +189,7 @@ class HashedBufferedStream implements BufferedProxyStreamInterface, BufferInterf * * @return \Generator */ - public function connectGenerator(ConnectionContext $ctx, string $header = ''): \Generator + public function connect(ConnectionContext $ctx, string $header = ''): \Generator { $this->write_hash = null; $this->write_check_after = 0; @@ -197,7 +197,7 @@ class HashedBufferedStream implements BufferedProxyStreamInterface, BufferInterf $this->read_hash = null; $this->read_check_after = 0; $this->read_check_pos = 0; - $this->stream = (yield $ctx->getStream($header)); + $this->stream = (yield from $ctx->getStream($header)); } /** * Async close. diff --git a/src/danog/MadelineProto/Stream/ConnectionContext.php b/src/danog/MadelineProto/Stream/ConnectionContext.php index a317cd94..6b1a76b2 100644 --- a/src/danog/MadelineProto/Stream/ConnectionContext.php +++ b/src/danog/MadelineProto/Stream/ConnectionContext.php @@ -421,7 +421,7 @@ class ConnectionContext if ($obj instanceof ProxyStreamInterface) { $obj->setExtra($extra); } - yield $obj->connect($this, $buffer); + yield from $obj->connect($this, $buffer); return $obj; } /** diff --git a/src/danog/MadelineProto/Stream/MTProtoTransport/AbridgedStream.php b/src/danog/MadelineProto/Stream/MTProtoTransport/AbridgedStream.php index d5b3717f..cdb1675d 100644 --- a/src/danog/MadelineProto/Stream/MTProtoTransport/AbridgedStream.php +++ b/src/danog/MadelineProto/Stream/MTProtoTransport/AbridgedStream.php @@ -43,9 +43,9 @@ class AbridgedStream implements BufferedStreamInterface, MTProtoBufferInterface * * @return \Generator */ - public function connectGenerator(ConnectionContext $ctx, string $header = ''): \Generator + public function connect(ConnectionContext $ctx, string $header = ''): \Generator { - $this->stream = (yield $ctx->getStream(\chr(239) . $header)); + $this->stream = (yield from $ctx->getStream(\chr(239) . $header)); } /** * Async close. diff --git a/src/danog/MadelineProto/Stream/MTProtoTransport/HttpStream.php b/src/danog/MadelineProto/Stream/MTProtoTransport/HttpStream.php index 96588670..723fcb42 100644 --- a/src/danog/MadelineProto/Stream/MTProtoTransport/HttpStream.php +++ b/src/danog/MadelineProto/Stream/MTProtoTransport/HttpStream.php @@ -53,10 +53,10 @@ class HttpStream implements MTProtoBufferInterface, BufferedProxyStreamInterface * * @return \Generator */ - public function connectGenerator(ConnectionContext $ctx, string $header = ''): \Generator + public function connect(ConnectionContext $ctx, string $header = ''): \Generator { $this->ctx = $ctx->getCtx(); - $this->stream = (yield $ctx->getStream($header)); + $this->stream = (yield from $ctx->getStream($header)); $this->uri = $ctx->getUri(); } /** @@ -147,7 +147,7 @@ class HttpStream implements MTProtoBufferInterface, BufferedProxyStreamInterface } if ($close) { $this->disconnect(); - yield $this->connect($this->ctx); + yield from $this->connect($this->ctx); } \danog\MadelineProto\Logger::log($read); $this->code = \danog\MadelineProto\Tools::packSignedInt(-$code); diff --git a/src/danog/MadelineProto/Stream/MTProtoTransport/HttpsStream.php b/src/danog/MadelineProto/Stream/MTProtoTransport/HttpsStream.php index 0ce77b05..7c258d18 100644 --- a/src/danog/MadelineProto/Stream/MTProtoTransport/HttpsStream.php +++ b/src/danog/MadelineProto/Stream/MTProtoTransport/HttpsStream.php @@ -37,9 +37,9 @@ class HttpsStream extends HttpStream implements MTProtoBufferInterface * * @return \Generator */ - public function connectGenerator(ConnectionContext $ctx, string $header = ''): \Generator + public function connect(ConnectionContext $ctx, string $header = ''): \Generator { - return parent::connectGenerator($ctx->getCtx()->secure(true), $header); + return parent::connect($ctx->getCtx()->secure(true), $header); } /** * {@inheritDoc} diff --git a/src/danog/MadelineProto/Stream/MTProtoTransport/IntermediatePaddedStream.php b/src/danog/MadelineProto/Stream/MTProtoTransport/IntermediatePaddedStream.php index b020d50d..66fe3ba9 100644 --- a/src/danog/MadelineProto/Stream/MTProtoTransport/IntermediatePaddedStream.php +++ b/src/danog/MadelineProto/Stream/MTProtoTransport/IntermediatePaddedStream.php @@ -45,9 +45,9 @@ class IntermediatePaddedStream implements BufferedStreamInterface, MTProtoBuffer * * @return \Generator */ - public function connectGenerator(ConnectionContext $ctx, string $header = ''): \Generator + public function connect(ConnectionContext $ctx, string $header = ''): \Generator { - $this->stream = (yield $ctx->getStream(\str_repeat(\chr(221), 4) . $header)); + $this->stream = (yield from $ctx->getStream(\str_repeat(\chr(221), 4) . $header)); } /** * Async close. diff --git a/src/danog/MadelineProto/Stream/MTProtoTransport/IntermediateStream.php b/src/danog/MadelineProto/Stream/MTProtoTransport/IntermediateStream.php index 02bda62c..ee3f2d10 100644 --- a/src/danog/MadelineProto/Stream/MTProtoTransport/IntermediateStream.php +++ b/src/danog/MadelineProto/Stream/MTProtoTransport/IntermediateStream.php @@ -45,9 +45,9 @@ class IntermediateStream implements BufferedStreamInterface, MTProtoBufferInterf * * @return \Generator */ - public function connectGenerator(ConnectionContext $ctx, string $header = ''): \Generator + public function connect(ConnectionContext $ctx, string $header = ''): \Generator { - $this->stream = (yield $ctx->getStream(\str_repeat(\chr(238), 4) . $header)); + $this->stream = (yield from $ctx->getStream(\str_repeat(\chr(238), 4) . $header)); } /** * Async close. diff --git a/src/danog/MadelineProto/Stream/MTProtoTransport/ObfuscatedStream.php b/src/danog/MadelineProto/Stream/MTProtoTransport/ObfuscatedStream.php index 1604b838..89dfa57d 100644 --- a/src/danog/MadelineProto/Stream/MTProtoTransport/ObfuscatedStream.php +++ b/src/danog/MadelineProto/Stream/MTProtoTransport/ObfuscatedStream.php @@ -43,7 +43,7 @@ class ObfuscatedStream extends CtrStream implements BufferedProxyStreamInterface * * @return \Generator */ - public function connectGenerator(ConnectionContext $ctx, string $header = ''): \Generator + public function connect(ConnectionContext $ctx, string $header = ''): \Generator { if (isset($this->extra['address'])) { $ctx = $ctx->getCtx(); @@ -67,7 +67,7 @@ class ObfuscatedStream extends CtrStream implements BufferedProxyStreamInterface $iv = \substr($random, 40, 16); $ivRev = \substr($reversed, 40, 16); parent::setExtra(['encrypt' => ['key' => $key, 'iv' => $iv], 'decrypt' => ['key' => $keyRev, 'iv' => $ivRev]]); - yield parent::connectGenerator($ctx); + yield from parent::connect($ctx); $random = \substr_replace($random, \substr(@$this->getEncryptor()->encrypt($random), 56, 8), 56, 8); yield $this->getStream()->write($random); } diff --git a/src/danog/MadelineProto/Stream/Proxy/HttpProxy.php b/src/danog/MadelineProto/Stream/Proxy/HttpProxy.php index 28d90c98..1a2c1dcc 100644 --- a/src/danog/MadelineProto/Stream/Proxy/HttpProxy.php +++ b/src/danog/MadelineProto/Stream/Proxy/HttpProxy.php @@ -44,7 +44,7 @@ class HttpProxy implements RawProxyStreamInterface, BufferedProxyStreamInterface * * @return \Generator */ - public function connectGenerator(ConnectionContext $ctx, string $header = ''): \Generator + public function connect(ConnectionContext $ctx, string $header = ''): \Generator { $ctx = $ctx->getCtx(); $uri = $ctx->getUri(); @@ -53,7 +53,7 @@ class HttpProxy implements RawProxyStreamInterface, BufferedProxyStreamInterface $ctx->setSocketContext($ctx->getSocketContext()->withTlsContext(new ClientTlsContext($uri->getHost()))); } $ctx->setUri('tcp://' . $this->extra['address'] . ':' . $this->extra['port'])->secure(false); - $this->stream = (yield $ctx->getStream()); + $this->stream = (yield from $ctx->getStream()); $address = $uri->getHost(); $port = $uri->getPort(); try { diff --git a/src/danog/MadelineProto/Stream/Proxy/SocksProxy.php b/src/danog/MadelineProto/Stream/Proxy/SocksProxy.php index a53d56bb..3362d4f0 100644 --- a/src/danog/MadelineProto/Stream/Proxy/SocksProxy.php +++ b/src/danog/MadelineProto/Stream/Proxy/SocksProxy.php @@ -45,7 +45,7 @@ class SocksProxy implements RawProxyStreamInterface, BufferedProxyStreamInterfac * * @return \Generator */ - public function connectGenerator(ConnectionContext $ctx, string $header = ''): \Generator + public function connect(ConnectionContext $ctx, string $header = ''): \Generator { $ctx = $ctx->getCtx(); $uri = $ctx->getUri(); @@ -58,7 +58,7 @@ class SocksProxy implements RawProxyStreamInterface, BufferedProxyStreamInterfac if (isset($this->extra['username']) && isset($this->extra['password'])) { $methods .= \chr(2); } - $this->stream = (yield $ctx->getStream(\chr(5) . \chr(\strlen($methods)) . $methods)); + $this->stream = (yield from $ctx->getStream(\chr(5) . \chr(\strlen($methods)) . $methods)); $l = 2; $buffer = yield $this->stream->getReadBuffer($l); $version = \ord(yield $buffer->bufferRead(1)); diff --git a/src/danog/MadelineProto/Stream/StreamInterface.php b/src/danog/MadelineProto/Stream/StreamInterface.php index ff4edeb6..043b2c91 100644 --- a/src/danog/MadelineProto/Stream/StreamInterface.php +++ b/src/danog/MadelineProto/Stream/StreamInterface.php @@ -35,9 +35,9 @@ interface StreamInterface * * @param ConnectionContext $ctx The connection context * - * @return Promise + * @return \Generator */ - public function connect(ConnectionContext $ctx, string $header = ''): Promise; + public function connect(ConnectionContext $ctx, string $header = ''): \Generator; /** * Disconnect from the server. * diff --git a/src/danog/MadelineProto/Stream/Transport/DefaultStream.php b/src/danog/MadelineProto/Stream/Transport/DefaultStream.php index 352be64b..99746b1a 100644 --- a/src/danog/MadelineProto/Stream/Transport/DefaultStream.php +++ b/src/danog/MadelineProto/Stream/Transport/DefaultStream.php @@ -60,7 +60,7 @@ class DefaultStream implements RawStreamInterface, ProxyStreamInterface { return $this->stream; } - public function connectGenerator(\danog\MadelineProto\Stream\ConnectionContext $ctx, string $header = ''): \Generator + public function connect(\danog\MadelineProto\Stream\ConnectionContext $ctx, string $header = ''): \Generator { $ctx = $ctx->getCtx(); $uri = $ctx->getUri(); diff --git a/src/danog/MadelineProto/Stream/Transport/PremadeStream.php b/src/danog/MadelineProto/Stream/Transport/PremadeStream.php index f6def9c4..150ac956 100644 --- a/src/danog/MadelineProto/Stream/Transport/PremadeStream.php +++ b/src/danog/MadelineProto/Stream/Transport/PremadeStream.php @@ -50,7 +50,7 @@ class PremadeStream implements RawStreamInterface, ProxyStreamInterface { return $this->stream; } - public function connectGenerator(ConnectionContext $ctx, string $header = ''): \Generator + public function connect(ConnectionContext $ctx, string $header = ''): \Generator { if ($header !== '') { yield $this->stream->write($header); diff --git a/src/danog/MadelineProto/Stream/Transport/WsStream.php b/src/danog/MadelineProto/Stream/Transport/WsStream.php index c7b4de8e..d22c6996 100644 --- a/src/danog/MadelineProto/Stream/Transport/WsStream.php +++ b/src/danog/MadelineProto/Stream/Transport/WsStream.php @@ -62,7 +62,7 @@ class WsStream implements RawStreamInterface, ProxyStreamInterface * * @return \Generator */ - public function connectGenerator(ConnectionContext $ctx, string $header = ''): \Generator + public function connect(ConnectionContext $ctx, string $header = ''): \Generator { if (!\class_exists(Connector::class)) { throw new \danog\MadelineProto\Exception('Please install amphp/websocket-client by running "composer require amphp/websocket-client:dev-master"'); diff --git a/src/danog/MadelineProto/Stream/Transport/WssStream.php b/src/danog/MadelineProto/Stream/Transport/WssStream.php index 38475d66..832e4cc8 100644 --- a/src/danog/MadelineProto/Stream/Transport/WssStream.php +++ b/src/danog/MadelineProto/Stream/Transport/WssStream.php @@ -35,9 +35,9 @@ class WssStream extends WsStream * * @return \Generator */ - public function connectGenerator(ConnectionContext $ctx, string $header = ''): \Generator + public function connect(ConnectionContext $ctx, string $header = ''): \Generator { - return parent::connectGenerator($ctx->getCtx()->secure(true), $header); + return parent::connect($ctx->getCtx()->secure(true), $header); } public static function getName(): string {