mirror of
https://github.com/bitinflow/expose.git
synced 2026-03-13 21:45:55 +00:00
wip
This commit is contained in:
42
app/Http/Controllers/Controller.php
Normal file
42
app/Http/Controllers/Controller.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Exception;
|
||||
use Ratchet\ConnectionInterface;
|
||||
use Ratchet\Http\HttpServerInterface;
|
||||
use Twig\Environment;
|
||||
use Twig\Loader\ArrayLoader;
|
||||
use function GuzzleHttp\Psr7\stream_for;
|
||||
|
||||
abstract class Controller implements HttpServerInterface
|
||||
{
|
||||
public function onClose(ConnectionInterface $connection)
|
||||
{
|
||||
unset($connection->requestBuffer);
|
||||
unset($connection->contentLength);
|
||||
unset($connection->request);
|
||||
}
|
||||
|
||||
public function onError(ConnectionInterface $connection, Exception $e)
|
||||
{
|
||||
}
|
||||
|
||||
public function onMessage(ConnectionInterface $from, $msg)
|
||||
{
|
||||
}
|
||||
|
||||
protected function getView(string $view, array $data = [])
|
||||
{
|
||||
$templatePath = implode(DIRECTORY_SEPARATOR, explode('.', $view));
|
||||
|
||||
$twig = new Environment(
|
||||
new ArrayLoader([
|
||||
'app' => file_get_contents(base_path('resources/views/server/layouts/app.twig')),
|
||||
'template' => file_get_contents(base_path('resources/views/'.$templatePath.'.twig')),
|
||||
])
|
||||
);
|
||||
|
||||
return stream_for($twig->render('template', $data));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user