Skip to content

Commit d1025e1

Browse files
Remove compatibility with 6.3
1 parent b4de865 commit d1025e1

21 files changed

+17
-390
lines changed

src/Maker/MakeAuthenticator.php

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
use Symfony\Bundle\MakerBundle\Security\SecurityControllerBuilder;
2525
use Symfony\Bundle\MakerBundle\Str;
2626
use Symfony\Bundle\MakerBundle\Util\ClassSourceManipulator;
27-
use Symfony\Bundle\MakerBundle\Util\FeatureSupportTrait;
2827
use Symfony\Bundle\MakerBundle\Util\UseStatementGenerator;
2928
use Symfony\Bundle\MakerBundle\Util\YamlManipulationFailedException;
3029
use Symfony\Bundle\MakerBundle\Util\YamlSourceManipulator;
@@ -65,7 +64,6 @@
6564
*/
6665
final class MakeAuthenticator extends AbstractMaker
6766
{
68-
use FeatureSupportTrait;
6967
private const AUTH_TYPE_EMPTY_AUTHENTICATOR = 'empty-authenticator';
7068
private const AUTH_TYPE_FORM_LOGIN = 'form-login';
7169

@@ -284,7 +282,7 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen
284282
$input->hasArgument('logout-setup') ? $input->getArgument('logout-setup') : false,
285283
$supportRememberMe,
286284
$alwaysRememberMe,
287-
$this->supportsLogoutRouteLoader() && !file_exists('config/routes/security.yaml'),
285+
!file_exists('config/routes/security.yaml'),
288286
)
289287
);
290288
}
@@ -390,10 +388,6 @@ private function generateFormLoginFiles(string $controllerClass, string $userNam
390388

391389
$this->securityControllerBuilder->addLoginMethod($manipulator);
392390

393-
if ($logoutSetup && !$this->supportsLogoutRouteLoader()) {
394-
$this->securityControllerBuilder->addLogoutMethod($manipulator);
395-
}
396-
397391
$this->generator->dumpFile($controllerPath, $manipulator->getSourceCode());
398392

399393
// create login form template
@@ -412,7 +406,7 @@ private function generateFormLoginFiles(string $controllerClass, string $userNam
412406
}
413407

414408
/** @return string[] */
415-
private function generateNextMessage(bool $securityYamlUpdated, string $authenticatorType, string $authenticatorClass, ?string $userClass, bool $logoutSetup, bool $supportRememberMe, bool $alwaysRememberMe, bool $defaultSecurityRoute): array
409+
private function generateNextMessage(bool $securityYamlUpdated, string $authenticatorType, string $authenticatorClass, ?string $userClass, bool $logoutSetup, bool $supportRememberMe, bool $alwaysRememberMe, bool $hasSecurityRouteFile): array
416410
{
417411
$nextTexts = ['Next:'];
418412
$nextTexts[] = '- Customize your new authenticator.';
@@ -441,7 +435,9 @@ private function generateNextMessage(bool $securityYamlUpdated, string $authenti
441435
}
442436

443437
// If the security.logout_route_loader is not loaded from the default flex recipe
444-
$nextTexts[] = '- Be sure to add the "logout" route to <info>config/routes/security.yaml</info> or upgrade the <info>symfony/security-bundle</info> recipe.';
438+
if (!$hasSecurityRouteFile) {
439+
$nextTexts[] = '- Be sure to add the "logout" route to <info>config/routes/security.yaml</info> or upgrade the <info>symfony/security-bundle</info> recipe.';
440+
}
445441

446442
return $nextTexts;
447443
}

src/Maker/Security/MakeFormLogin.php

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@
2828
use Symfony\Bundle\MakerBundle\Security\SecurityConfigUpdater;
2929
use Symfony\Bundle\MakerBundle\Security\SecurityControllerBuilder;
3030
use Symfony\Bundle\MakerBundle\Str;
31-
use Symfony\Bundle\MakerBundle\Util\ClassSourceManipulator;
32-
use Symfony\Bundle\MakerBundle\Util\FeatureSupportTrait;
3331
use Symfony\Bundle\MakerBundle\Util\UseStatementGenerator;
3432
use Symfony\Bundle\MakerBundle\Util\YamlSourceManipulator;
3533
use Symfony\Bundle\MakerBundle\Validator;
@@ -67,8 +65,11 @@ final class MakeFormLogin extends AbstractMaker
6765
public function __construct(
6866
private FileManager $fileManager,
6967
private SecurityConfigUpdater $securityConfigUpdater,
70-
private SecurityControllerBuilder $securityControllerBuilder,
68+
private ?SecurityControllerBuilder $securityControllerBuilder = null,
7169
) {
70+
if (null !== $this->securityControllerBuilder) {
71+
trigger_deprecation('symfony/maker-bundle', 'v1.61', 'The "%s $securityControllerBuilder" constructor argument is deprecated, you should stop using it', SecurityControllerBuilder::class);
72+
}
7273
}
7374

7475
public static function getCommandName(): string
@@ -146,7 +147,7 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen
146147
$controllerNameDetails = $generator->createClassNameDetails($this->controllerName, 'Controller\\', 'Controller');
147148
$templatePath = strtolower($controllerNameDetails->getRelativeNameWithoutSuffix());
148149

149-
$controllerPath = $generator->generateController(
150+
$generator->generateController(
150151
$controllerNameDetails->getFullName(),
151152
'security/formLogin/LoginController.tpl.php',
152153
[
@@ -156,14 +157,6 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen
156157
]
157158
);
158159

159-
if ($this->willLogout && !$this->supportsLogoutRouteLoader()) {
160-
$manipulator = new ClassSourceManipulator($generator->getFileContentsForPendingOperation($controllerPath));
161-
162-
$this->securityControllerBuilder->addLogoutMethod($manipulator);
163-
164-
$generator->dumpFile($controllerPath, $manipulator->getSourceCode());
165-
}
166-
167160
$generator->generateTemplate(
168161
sprintf('%s/login.html.twig', $templatePath),
169162
'security/formLogin/login_form.tpl.php',

src/Resources/config/makers.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,6 @@
156156
<service id="maker.maker.make_form_login" class="Symfony\Bundle\MakerBundle\Maker\Security\MakeFormLogin">
157157
<argument type="service" id="maker.file_manager" />
158158
<argument type="service" id="maker.security_config_updater" />
159-
<argument type="service" id="maker.security_controller_builder" />
160159
<tag name="maker.command" />
161160
</service>
162161

src/Security/SecurityControllerBuilder.php

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -66,19 +66,4 @@ public function addLoginMethod(ClassSourceManipulator $manipulator): void
6666
);
6767
$manipulator->addMethodBuilder($loginMethodBuilder);
6868
}
69-
70-
public function addLogoutMethod(ClassSourceManipulator $manipulator): void
71-
{
72-
$logoutMethodBuilder = $manipulator->createMethodBuilder('logout', 'void', false);
73-
74-
$logoutMethodBuilder->addAttribute($manipulator->buildAttributeNode(Route::class, ['path' => '/logout', 'name' => 'app_logout']));
75-
76-
$manipulator->addUseStatementIfNecessary(Route::class);
77-
$manipulator->addMethodBody($logoutMethodBuilder, <<<'CODE'
78-
<?php
79-
throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.');
80-
CODE
81-
);
82-
$manipulator->addMethodBuilder($logoutMethodBuilder);
83-
}
8469
}

src/Util/FeatureSupportTrait.php

Lines changed: 0 additions & 35 deletions
This file was deleted.

tests/Maker/MakeAuthenticatorTest.php

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -272,50 +272,6 @@ public function getTestDetails(): \Generator
272272
$this->assertFileExists($runner->getPath('templates/security/login.html.twig'));
273273
$this->assertFileExists($runner->getPath('src/Security/AppCustomAuthenticator.php'));
274274

275-
$securityConfig = $runner->readYaml('config/packages/security.yaml');
276-
$this->assertEquals(
277-
'app_logout',
278-
$securityConfig['security']['firewalls']['main']['logout']['path']
279-
);
280-
}),
281-
];
282-
283-
yield 'auth_login_form_user_entity_with_logout_route_loader' => [$this->createMakerTest()
284-
->addExtraDependencies('doctrine', 'twig', 'symfony/form')
285-
->run(function (MakerTestRunner $runner) {
286-
$this->makeUser($runner, 'userEmail');
287-
// We pretend that the LogoutRouteLoader is registered
288-
$runner->addToAutoloader('Symfony\\Bundle\\SecurityBundle\\Routing\\', \dirname(__DIR__).'/fixtures/security-bundle/routing/');
289-
$runner->modifyYamlFile('config/services.yaml', function (array $config) {
290-
$config['services']['security.route_loader.logout'] = [
291-
'class' => 'Symfony\Bundle\SecurityBundle\\Routing\\LogoutRouteLoader',
292-
'tags' => ['routing.route_loader'],
293-
];
294-
295-
return $config;
296-
});
297-
$output = $runner->runMaker([
298-
// authenticator type => login-form
299-
1,
300-
// class name
301-
'AppCustomAuthenticator',
302-
// controller name
303-
'SecurityController',
304-
// logout support
305-
'yes',
306-
// remember me support => no
307-
'no',
308-
]);
309-
310-
$this->runLoginTest($runner, 'userEmail', true, 'App\\Entity\\User', true);
311-
312-
$this->assertStringContainsString('Success', $output);
313-
314-
$this->assertFileExists($runner->getPath('src/Controller/SecurityController.php'));
315-
$this->assertFileEquals(\dirname(__DIR__).'/fixtures/make-auth/SecurityController-no-logout.php', $runner->getPath('src/Controller/SecurityController.php'));
316-
$this->assertFileExists($runner->getPath('templates/security/login.html.twig'));
317-
$this->assertFileExists($runner->getPath('src/Security/AppCustomAuthenticator.php'));
318-
319275
$securityConfig = $runner->readYaml('config/packages/security.yaml');
320276
$this->assertEquals(
321277
'/logout',

tests/Maker/Security/MakeFormLoginTest.php

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function getTestDetails(): \Generator
4848
$this->assertSame('app_login', $securityConfig['security']['firewalls']['main']['form_login']['login_path']);
4949
$this->assertSame('app_login', $securityConfig['security']['firewalls']['main']['form_login']['check_path']);
5050
$this->assertTrue($securityConfig['security']['firewalls']['main']['form_login']['enable_csrf']);
51-
$this->assertSame('app_logout', $securityConfig['security']['firewalls']['main']['logout']['path']);
51+
$this->assertSame('/logout', $securityConfig['security']['firewalls']['main']['logout']['path']);
5252

5353
$this->runLoginTest($runner);
5454
}),
@@ -66,7 +66,7 @@ public function getTestDetails(): \Generator
6666
$this->assertStringContainsString('Success', $output);
6767
$fixturePath = \dirname(__DIR__, 2).'/fixtures/security/make-form-login/expected';
6868

69-
$this->assertFileEquals($fixturePath.'/SecurityControllerWithoutLogout.php', $runner->getPath('src/Controller/SecurityController.php'));
69+
$this->assertFileEquals($fixturePath.'/SecurityController.php', $runner->getPath('src/Controller/SecurityController.php'));
7070
$this->assertFileEquals($fixturePath.'/login_no_logout.html.twig', $runner->getPath('templates/security/login.html.twig'));
7171

7272
$securityConfig = $runner->readYaml('config/packages/security.yaml');
@@ -96,7 +96,7 @@ public function getTestDetails(): \Generator
9696

9797
$this->assertSame('app_login', $securityConfig['security']['firewalls']['main']['form_login']['login_path']);
9898
$this->assertSame('app_login', $securityConfig['security']['firewalls']['main']['form_login']['check_path']);
99-
$this->assertSame('app_logout', $securityConfig['security']['firewalls']['main']['logout']['path']);
99+
$this->assertSame('/logout', $securityConfig['security']['firewalls']['main']['logout']['path']);
100100
}),
101101
];
102102

@@ -124,36 +124,12 @@ public function getTestDetails(): \Generator
124124
$this->assertSame('app_login', $securityConfig['security']['firewalls']['main']['form_login']['login_path']);
125125
$this->assertSame('app_login', $securityConfig['security']['firewalls']['main']['form_login']['check_path']);
126126
$this->assertTrue($securityConfig['security']['firewalls']['main']['form_login']['enable_csrf']);
127-
$this->assertSame('app_logout', $securityConfig['security']['firewalls']['main']['logout']['path']);
127+
$this->assertSame('/logout', $securityConfig['security']['firewalls']['main']['logout']['path']);
128128

129129
$runner->configureDatabase();
130130
$runner->runTests();
131131
}),
132132
];
133-
134-
yield 'generates_form_login_with_logout_with_route_loader' => [$this->createMakerTest()
135-
->run(function (MakerTestRunner $runner) {
136-
// We pretend that the LogoutRouteLoader is registered
137-
$runner->addToAutoloader('Symfony\\Bundle\\SecurityBundle\\Routing\\', \dirname(__DIR__, 2).'/fixtures/security-bundle/routing');
138-
$this->makeUser($runner);
139-
$output = $runner->runMaker([
140-
'SecurityController', // Controller Name
141-
'y', // Generate Logout
142-
]);
143-
144-
$this->assertStringContainsString('Success', $output);
145-
$fixturePath = \dirname(__DIR__, 2).'/fixtures/security/make-form-login/expected';
146-
147-
$this->assertFileEquals($fixturePath.'/SecurityControllerLogoutRouteLoader.php', $runner->getPath('src/Controller/SecurityController.php'));
148-
$this->assertFileEquals($fixturePath.'/login_routeloader_logout.html.twig', $runner->getPath('templates/security/login.html.twig'));
149-
150-
$securityConfig = $runner->readYaml('config/packages/security.yaml');
151-
152-
$this->assertSame('app_login', $securityConfig['security']['firewalls']['main']['form_login']['login_path']);
153-
$this->assertSame('app_login', $securityConfig['security']['firewalls']['main']['form_login']['check_path']);
154-
$this->assertSame('/logout', $securityConfig['security']['firewalls']['main']['logout']['path']);
155-
}),
156-
];
157133
}
158134

159135
private function runLoginTest(MakerTestRunner $runner): void

tests/Security/SecurityConfigUpdaterTest.php

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,11 @@ public function getUserClassTests(): \Generator
104104
/**
105105
* @dataProvider getAuthenticatorTests
106106
*/
107-
public function testUpdateForAuthenticator(string $firewallName, $entryPoint, string $expectedSourceFilename, string $startingSourceFilename, bool $logoutSetup, bool $supportRememberMe, bool $alwaysRememberMe, bool $useLogoutRouteLoader = false): void
107+
public function testUpdateForAuthenticator(string $firewallName, $entryPoint, string $expectedSourceFilename, string $startingSourceFilename, bool $logoutSetup, bool $supportRememberMe, bool $alwaysRememberMe): void
108108
{
109109
$this->createLogger();
110110

111111
$updater = new SecurityConfigUpdater($this->ysmLogger);
112-
if ($useLogoutRouteLoader) {
113-
$updater->forceSupportLogoutRouteLoader();
114-
}
115112
$source = file_get_contents(__DIR__.'/yaml_fixtures/source/'.$startingSourceFilename);
116113
$actualSource = $updater->updateForAuthenticator($source, $firewallName, $entryPoint, 'App\\Security\\AppCustomAuthenticator', $logoutSetup, $supportRememberMe, $alwaysRememberMe);
117114
$expectedSource = file_get_contents(__DIR__.'/yaml_fixtures/expected_authenticator/'.$expectedSourceFilename);
@@ -200,17 +197,6 @@ public function getAuthenticatorTests(): \Generator
200197
true,
201198
true,
202199
];
203-
204-
yield 'simple_security_with_firewalls_and_logout_via_loader' => [
205-
'main',
206-
'App\\Security\\AppCustomAuthenticator',
207-
'simple_security_with_firewalls_and_logout_via_loader.yaml',
208-
'simple_security_with_firewalls_and_logout.yaml',
209-
true,
210-
false,
211-
false,
212-
true,
213-
];
214200
}
215201

216202
public function testUpdateForFormLogin(): void

tests/Security/SecurityControllerBuilderTest.php

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -27,28 +27,6 @@ public function testLoginMethod(): void
2727
);
2828
}
2929

30-
public function testLogoutMethod(): void
31-
{
32-
$this->runMethodTest(
33-
'addLogoutMethod',
34-
sprintf('%s/%s', $this->expectedBasePath, 'SecurityController_logout.php')
35-
);
36-
}
37-
38-
public function testLoginAndLogoutMethod(): void
39-
{
40-
$builder = new SecurityControllerBuilder();
41-
$csm = $this->getClassSourceManipulator();
42-
43-
$builder->addLoginMethod($csm);
44-
$builder->addLogoutMethod($csm);
45-
46-
$this->assertStringEqualsFile(
47-
sprintf('%s/%s', $this->expectedBasePath, 'SecurityController_login_logout.php'),
48-
$csm->getSourceCode()
49-
);
50-
}
51-
5230
private function runMethodTest(string $builderMethod, string $expectedFilePath): void
5331
{
5432
$builder = new SecurityControllerBuilder();

tests/Security/fixtures/expected/SecurityController_login_logout.php

Lines changed: 0 additions & 32 deletions
This file was deleted.

tests/Security/fixtures/expected/SecurityController_logout.php

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)