This commit is contained in:
Marcel Pociot
2020-04-30 15:17:25 +02:00
parent 0dfda0825c
commit a972c8581c
24 changed files with 444 additions and 29 deletions

View File

@@ -2,13 +2,14 @@
namespace App\Http\Controllers\Concerns;
use Ratchet\ConnectionInterface;
use Twig\Environment;
use Twig\Loader\ArrayLoader;
use function GuzzleHttp\Psr7\stream_for;
trait LoadsViews
{
protected function getView(string $view, array $data = [])
protected function getView(ConnectionInterface $connection, string $view, array $data = [])
{
$templatePath = implode(DIRECTORY_SEPARATOR, explode('.', $view));
@@ -19,6 +20,10 @@ trait LoadsViews
])
);
$data = array_merge($data, [
'request' => $connection->laravelRequest ?? null,
]);
return stream_for($twig->render('template', $data));
}
}

View File

@@ -26,10 +26,10 @@ trait ParsesIncomingRequest
protected function checkContentLength(ConnectionInterface $connection)
{
if (strlen($connection->requestBuffer) === $connection->contentLength) {
$laravelRequest = $this->createLaravelRequest($connection);
$connection->laravelRequest = $this->createLaravelRequest($connection);
if ($this->shouldHandleRequest($laravelRequest, $connection)) {
$this->handle($laravelRequest, $connection);
if ($this->shouldHandleRequest($connection->laravelRequest, $connection)) {
$this->handle($connection->laravelRequest, $connection);
}
if (!$this->keepConnectionOpen) {