File tree Expand file tree Collapse file tree 4 files changed +55
-11
lines changed
Expand file tree Collapse file tree 4 files changed +55
-11
lines changed Original file line number Diff line number Diff line change 44
55namespace App \Controller ;
66
7- use App \Repository \UserRepository ;
8- use Doctrine \DBAL \Connection ;
7+ use App \Data \Controller \ListUsersActionData ;
98use Symfony \Bundle \FrameworkBundle \Controller \AbstractController ;
109use Symfony \Component \HttpFoundation \Response ;
1110use Symfony \Component \HttpKernel \Attribute \AsController ;
1514final class ListUsersAction extends AbstractController
1615{
1716 #[Route(path: '/users ' , name: self ::class)]
18- public function __invoke (Connection $ conn , UserRepository $ userRepository ): Response
17+ public function __invoke (ListUsersActionData $ listUsersActionData ): Response
1918 {
2019 return $ this ->render (self ::class.'.html.twig ' , [
21- 'users_dbal ' => $ conn ->fetchAllAssociative ('SELECT * FROM user ' ),
22- 'users_orm ' => $ userRepository ->findAll (),
20+ 'data ' => $ listUsersActionData ->getData (),
2321 ]);
2422 }
2523}
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace App \Controller ;
6+
7+ use App \Entity \User ;
8+
9+ final class ListUsersActionDto
10+ {
11+ /**
12+ * @param list<array<string, mixed>> $usersDbal
13+ * @param array<User> $usersOrm
14+ */
15+ public function __construct (
16+ public array $ usersDbal ,
17+ public array $ usersOrm ,
18+ ) {
19+ }
20+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace App \Data \Controller ;
6+
7+ use App \Controller \ListUsersActionDto ;
8+ use App \Repository \UserRepository ;
9+ use Doctrine \DBAL \Connection ;
10+
11+ final readonly class ListUsersActionData
12+ {
13+ public function __construct (
14+ private Connection $ conn ,
15+ private UserRepository $ userRepository ,
16+ ) {
17+ }
18+
19+ public function getData (): ListUsersActionDto
20+ {
21+ return new ListUsersActionDto (
22+ usersDbal: $ this ->conn ->fetchAllAssociative ('SELECT * FROM user ' ),
23+ usersOrm: $ this ->userRepository ->findAll (),
24+ );
25+ }
26+ }
Original file line number Diff line number Diff line change 88 <h3 >Doctrine DBAL</h3 >
99
1010 <code >
11- 'users_dbal' => $ conn->fetchAllAssociative('SELECT * FROM user'),
11+ usersDbal: $this-> conn->fetchAllAssociative('SELECT * FROM user'),
1212 </code >
1313
1414 <table class =" striped" >
2222 </tr >
2323 </thead >
2424 <tbody >
25- {% for user in users_dbal %}
25+ {% for user in data . usersDbal %}
2626 <tr >
2727 <td >{{ user .id }}</td >
2828 <td >{{ user .email }}</td >
3535 <tfoot >
3636 <tr >
3737 <th colspan =" 5" scope =" row" >
38- There are <b >{{ users_dbal | length }}</b > user(s).
38+ There are <b >{{ data . usersDbal | length }}</b > user(s).
3939 </th >
4040 </tr >
4141 </tfoot >
4646 <h3 >Doctrine ORM</h3 >
4747
4848 <code >
49- 'users_orm' => $ userRepository->findAll(),
49+ usersOrm: $this-> userRepository->findAll(),
5050 </code >
5151
5252 <table class =" striped" >
6060 </tr >
6161 </thead >
6262 <tbody >
63- {% for user in users_orm %}
63+ {% for user in data . usersOrm %}
6464 <tr >
6565 <td >{{ user .id }}</td >
6666 <td >{{ user .email }}</td >
7373 <tfoot >
7474 <tr >
7575 <th colspan =" 5" scope =" row" >
76- There are <b >{{ users_orm | length }}</b > user(s).
76+ There are <b >{{ data . usersOrm | length }}</b > user(s).
7777 </th >
7878 </tr >
7979 </tfoot >
You can’t perform that action at this time.
0 commit comments