1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- <?php
- /*
- * This file is a part of the DiscordPHP-Http project.
- *
- * Copyright (c) 2021-present David Cole <david.cole1340@gmail.com>
- *
- * This file is subject to the MIT license that is bundled
- * with this source code in the LICENSE file.
- */
- namespace Discord\Http\Drivers;
- use Discord\Http\DriverInterface;
- use Discord\Http\Request;
- use React\EventLoop\LoopInterface;
- use React\Http\Browser;
- use React\Promise\ExtendedPromiseInterface;
- use React\Socket\Connector;
- /**
- * react/http driver for Discord HTTP client.
- *
- * @author David Cole <david.cole1340@gmail.com>
- */
- class React implements DriverInterface
- {
- /**
- * ReactPHP event loop.
- *
- * @var LoopInterface
- */
- protected $loop;
- /**
- * ReactPHP/HTTP browser.
- *
- * @var Browser
- */
- protected $browser;
- /**
- * Constructs the Guzzle driver.
- *
- * @param LoopInterface $loop
- * @param array $options
- */
- public function __construct(LoopInterface $loop, array $options = [])
- {
- $this->loop = $loop;
- // Allow 400 and 500 HTTP requests to be resolved rather than rejected.
- $browser = new Browser($loop, new Connector($loop, $options));
- $this->browser = $browser->withRejectErrorResponse(false);
- }
- public function runRequest(Request $request): ExtendedPromiseInterface
- {
- return $this->browser->{$request->getMethod()}(
- $request->getUrl(),
- $request->getHeaders(),
- $request->getContent()
- );
- }
- }
|