feat: ship the /team page with the in-memory roster
@@ -10,7 +10,7 @@ final readonly class ViewTeamadded: use App\Team\Infrastructure\Repository\InMemoryMemberRepository;use Symfony\Component\HttpFoundation\Exception\NotFoundHttpException;use Symfony\Component\HttpFoundation\Request;use Symfony\Component\HttpFoundation\Response;use Symfony\Component\HttpKernel\Attribute\AsController;use Symfony\Component\Routing\Attribute\Route;added: use Twig\Environment;Could we alias this import to Twig to make it a little more understandable?
What about extending AbstractController and use the render() method?
#[AsController]final readonly class ViewTeam{ public function __construct(added: private Environment $twig,added: private InMemoryMemberRepository $memberRepository,This should depend on an interface instead to avoid coupling to implementation details
👍 That Repository ((opens in a new tab)) contract belongs to the Domain layer IMHO.
To target a specific implementation, you can use the Autowire attribute ((opens in a new tab)).
) { } #[Route(name: 'app_team', path: '/team')] public function __invoke(Request $request): Response {removed: return new Response();added: if ('GET' !== $request->getMethod()) {added: throw new NotFoundHttpException();While it works, #[Route(methods: ['GET'])] is a better way to achieve this.
Indeed, better leverage Symfony Routing capabilities so you can focus on the business logic.
added: }added: added: return new Response($this->twig->render('pages/team/index.html.twig', [added: 'members' => $this->memberRepository->findAll(),Should it return a paginated result instead?
AFAIK, baksla.sh isn't gonna have enough members to need pagination anytime soon 😉
Agreed, and while we're at it: skip render() entirely with the #[Template] attribute ((opens in a new tab)). Just return the array, no more Environment needed.
added: ])); }}