Skip to content

Instantly share code, notes, and snippets.

@BackEndTea
Created March 7, 2021 09:59
Show Gist options
  • Save BackEndTea/6256665f042fc499d8be58599c631d18 to your computer and use it in GitHub Desktop.
Save BackEndTea/6256665f042fc499d8be58599c631d18 to your computer and use it in GitHub Desktop.
<?php
namespace App\Controller;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Security\Core\Security;
use Twig\Environment;
class AccountPageActionV1
{
public function __construct(
private Environment $twig,
private Security $security
) {}
public function __invoke(): Response
{
// Deal with things
return new Response(
$this->twig->render('account/view.html.twig', [
'user' => $this->security->getUser(),
])
);
}
}
class AccountPageActionV2
{
public function __construct(
private AccountPageView $view,
private Security $security
) {}
public function __invoke(): Response
{
// Deal with things
return new Response(
$this->view->render($this->security->getUser())
);
}
}
class AccountPageView
{
public function __construct(
private Environment $twig,
private Security $security
) {}
public function render(User $user) {
return $this->twig->render('account/view.html.twig', [
'user' => $this->security->getUser(),
]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment