This commit is contained in:
Marcel Pociot
2020-04-25 11:42:40 +02:00
parent c89f6b38ea
commit 28c4009dff
16 changed files with 81 additions and 74 deletions

View File

@@ -5,6 +5,9 @@ namespace App\HttpServer\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
{
@@ -22,4 +25,17 @@ abstract class Controller implements HttpServerInterface
public function onMessage(ConnectionInterface $from, $msg)
{
}
protected function getView(string $view, array $data)
{
$templatePath = implode(DIRECTORY_SEPARATOR, explode('.', $view));
$twig = new Environment(
new ArrayLoader([
'template' => file_get_contents(base_path('resources/views/'.$templatePath.'.twig')),
])
);
return stream_for($twig->render('template', $data));
}
}