|
1 | 1 | <?php
|
2 | 2 |
|
3 | 3 | use Symfony\Bundle\MakerBundle\FileManager;
|
4 |
| -use Symfony\Bundle\MakerBundle\Util\YamlSourceManipulator; |
5 | 4 |
|
6 | 5 | return [
|
7 | 6 | 'description' => 'Create login form and tests.',
|
|
14 | 13 | 'symfony/stopwatch' => 'dev',
|
15 | 14 | ],
|
16 | 15 | 'configure' => function(FileManager $files) {
|
17 |
| - $services = new YamlSourceManipulator($files->getFileContents('config/services.yaml')); |
18 |
| - $data = $services->getData(); |
19 |
| - $data['services']['App\Security\LoginUser']['$authenticator'] ='@security.authenticator.form_login.main'; |
20 |
| - $services->setData($data); |
21 |
| - $files->dumpFile('config/services.yaml', $services->getContents()); |
| 16 | + // add LoginUser service |
| 17 | + $files->manipulateYaml('config/services.yaml', function(array $data) { |
| 18 | + $data['services']['App\Security\LoginUser']['$authenticator'] ='@security.authenticator.form_login.main'; |
22 | 19 |
|
23 |
| - $security = new YamlSourceManipulator($files->getFileContents('config/packages/security.yaml')); |
24 |
| - $data = $security->getData(); |
25 |
| - $data['security']['providers'] = [ |
26 |
| - 'app_user_provider' => [ |
27 |
| - 'entity' => [ |
28 |
| - 'class' => 'App\Entity\User', |
29 |
| - 'property' => 'email', |
| 20 | + return $data; |
| 21 | + }); |
| 22 | + |
| 23 | + // make security.yaml adjustments |
| 24 | + $files->manipulateYaml('config/packages/security.yaml', function(array $data) { |
| 25 | + $data['security']['providers'] = [ |
| 26 | + 'app_user_provider' => [ |
| 27 | + 'entity' => [ |
| 28 | + 'class' => 'App\Entity\User', |
| 29 | + 'property' => 'email', |
| 30 | + ], |
| 31 | + ], |
| 32 | + ]; |
| 33 | + $data['security']['firewalls']['main'] = [ |
| 34 | + 'lazy' => true, |
| 35 | + 'provider' => 'app_user_provider', |
| 36 | + 'form_login' => [ |
| 37 | + 'login_path' => 'login', |
| 38 | + 'check_path' => 'login', |
| 39 | + 'username_parameter' => 'email', |
| 40 | + 'password_parameter' => 'password', |
| 41 | + 'enable_csrf' => true, |
| 42 | + ], |
| 43 | + 'logout' => [ |
| 44 | + 'path' => 'logout', |
| 45 | + 'target' => 'homepage', |
30 | 46 | ],
|
31 |
| - ], |
32 |
| - ]; |
33 |
| - $data['security']['firewalls']['main'] = [ |
34 |
| - 'lazy' => true, |
35 |
| - 'provider' => 'app_user_provider', |
36 |
| - 'form_login' => [ |
37 |
| - 'login_path' => 'login', |
38 |
| - 'check_path' => 'login', |
39 |
| - 'username_parameter' => 'email', |
40 |
| - 'password_parameter' => 'password', |
41 |
| - 'enable_csrf' => true, |
42 |
| - ], |
43 |
| - 'logout' => [ |
44 |
| - 'path' => 'logout', |
45 |
| - 'target' => 'homepage', |
46 |
| - ], |
47 |
| - 'remember_me' => [ |
48 |
| - 'secret' => '%kernel.secret%', |
49 |
| - 'secure' => 'auto', |
50 |
| - 'samesite' => 'lax', |
51 |
| - ], |
52 |
| - ]; |
53 |
| - $security->setData($data); |
54 |
| - $files->dumpFile('config/packages/security.yaml', $security->getContents()); |
| 47 | + 'remember_me' => [ |
| 48 | + 'secret' => '%kernel.secret%', |
| 49 | + 'secure' => 'auto', |
| 50 | + 'samesite' => 'lax', |
| 51 | + ], |
| 52 | + ]; |
| 53 | + |
| 54 | + return $data; |
| 55 | + }); |
55 | 56 | },
|
56 | 57 | ];
|
0 commit comments