. * * @author Daniil Gentili * @copyright 2016-2020 Daniil Gentili * @license https://opensource.org/licenses/AGPL-3.0 AGPLv3 * * @link https://docs.madelineproto.xyz MadelineProto documentation */ namespace danog\MadelineProto\Wrappers; use \danog\MadelineProto\MTProto; use function Amp\ByteStream\getOutputBufferStream; trait Templates { /** * Echo page to console. * * @param string $message Error message * * @return \Generator */ private function webEcho(string $message = ''): \Generator { $stdout = getOutputBufferStream(); switch (yield $this->getAuthorization()) { case MTProto::NOT_LOGGED_IN: if (isset($_POST['type'])) { if ($_POST['type'] === 'phone') { yield $stdout->write($this->webEchoTemplate('Enter your phone number
'.$message.'', '')); } else { yield $stdout->write($this->webEchoTemplate('Enter your bot token
'.$message.'', '')); } } else { yield $stdout->write($this->webEchoTemplate('Do you want to login as user or bot?
'.$message.'', '')); } break; case MTProto::WAITING_CODE: yield $stdout->write($this->webEchoTemplate('Enter your code
'.$message.'', '')); break; case MTProto::WAITING_PASSWORD: yield $stdout->write($this->webEchoTemplate('Enter your password
'.$message.'', '')); break; case MTProto::WAITING_SIGNUP: yield $stdout->write($this->webEchoTemplate('Sign up please
'.$message.'', '')); break; } } /** * Web template. * * @var string */ private $web_template = 'MadelineProto

MadelineProto

%s

%s

'; /** * Format message according to template. * * @param string $message Message * @param string $form Form contents * * @return string */ private function webEchoTemplate(string $message, string $form): string { return \sprintf($this->web_template, $form, $message); } /** * Get web template. * * @return string */ public function getWebTemplate(): string { return $this->web_template; } /** * Set web template. * * @param string $template Template * * @return void */ public function setWebTemplate(string $template): void { $this->web_template = $template; } }