mirror of
https://github.com/bitinflow/expose.git
synced 2026-03-14 05:55:54 +00:00
wip
This commit is contained in:
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,19 +16,12 @@ class DashboardController extends Controller
|
||||
str(new Response(
|
||||
200,
|
||||
['Content-Type' => 'text/html'],
|
||||
$this->getView()
|
||||
$this->getView('client.dashboard', [
|
||||
'subdomains' => Client::$subdomains,
|
||||
])
|
||||
))
|
||||
);
|
||||
|
||||
$connection->close();
|
||||
}
|
||||
|
||||
protected function getView(): string
|
||||
{
|
||||
$view = file_get_contents(base_path('resources/views/index.html'));
|
||||
|
||||
$view = str_replace('%subdomains%', implode(' ', Client::$subdomains), $view);
|
||||
|
||||
return $view;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user