Skip to content

Commit 2bce3ed

Browse files
committed
Merge branch 'pull/36'
* pull/36: fabbot removing some of the "empty" parts fixing bad class fixing copy pasta! Adding a new make:auth:empty
2 parents 42ec3bd + e033cd0 commit 2bce3ed

File tree

4 files changed

+200
-63
lines changed

4 files changed

+200
-63
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bundle\MakerBundle\Command;
13+
14+
use Symfony\Bundle\MakerBundle\ConsoleStyle;
15+
use Symfony\Bundle\MakerBundle\DependencyBuilder;
16+
use Symfony\Bundle\MakerBundle\Str;
17+
use Symfony\Bundle\MakerBundle\Validator;
18+
use Symfony\Component\Console\Input\InputArgument;
19+
use Symfony\Bundle\SecurityBundle\SecurityBundle;
20+
21+
/**
22+
* @author Ryan Weaver <[email protected]>
23+
*/
24+
final class MakeAuthenticatorCommand extends AbstractCommand
25+
{
26+
protected static $defaultName = 'make:auth';
27+
28+
public function configure()
29+
{
30+
$this
31+
->setDescription('Creates an empty Guard authenticator')
32+
->addArgument('authenticator-class', InputArgument::OPTIONAL, 'The class name of the authenticator to create (e.g. <fg=yellow>AppCustomAuthenticator</>)')
33+
->setHelp(file_get_contents(__DIR__.'/../Resources/help/MakeAuth.txt'))
34+
;
35+
}
36+
37+
protected function getParameters(): array
38+
{
39+
$className = Str::asClassName($this->input->getArgument('authenticator-class'));
40+
Validator::validateClassName($className);
41+
42+
return array(
43+
'class_name' => $className,
44+
);
45+
}
46+
47+
protected function getFiles(array $params): array
48+
{
49+
return array(
50+
__DIR__.'/../Resources/skeleton/authenticator/Empty.php.txt' => 'src/Security/'.$params['class_name'].'.php',
51+
);
52+
}
53+
54+
protected function writeNextStepsMessage(array $params, ConsoleStyle $io)
55+
{
56+
$io->text(array(
57+
'Next: Customize your new authenticator.',
58+
'Then, configure the "guard" key on your firewall to use it.',
59+
));
60+
}
61+
62+
protected function configureDependencies(DependencyBuilder $dependencies)
63+
{
64+
$dependencies->addClassDependency(
65+
SecurityBundle::class,
66+
'security'
67+
);
68+
}
69+
}

src/Resources/help/MakeAuth.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
The <info>%command.name%</info> command generates an empty
2+
Guard Authenticator class.
3+
4+
<info>php %command.full_name% AppCustomAuthenticator</info>
5+
6+
If the argument is missing, the command will ask for the class name interactively.
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
3+
namespace App\Security;
4+
5+
use Symfony\Component\HttpFoundation\Request;
6+
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
7+
use Symfony\Component\Security\Core\Exception\AuthenticationException;
8+
use Symfony\Component\Security\Core\User\UserInterface;
9+
use Symfony\Component\Security\Core\User\UserProviderInterface;
10+
use Symfony\Component\Security\Guard\GuardAuthenticator;
11+
12+
class {{ class_name }} extends GuardAuthenticator
13+
{
14+
public function supports(Request $request)
15+
{
16+
17+
}
18+
19+
public function getCredentials(Request $request)
20+
{
21+
22+
}
23+
24+
public function getUser($credentials, UserProviderInterface $userProvider)
25+
{
26+
27+
}
28+
29+
public function checkCredentials($credentials, UserInterface $user)
30+
{
31+
32+
}
33+
34+
public function onAuthenticationFailure(Request $request, AuthenticationException $exception)
35+
{
36+
37+
}
38+
39+
public function onAuthenticationSuccess(Request $request, TokenInterface $token, $providerKey)
40+
{
41+
42+
}
43+
44+
public function supportsRememberMe()
45+
{
46+
47+
}
48+
49+
public function start(Request $request, AuthenticationException $authException = null)
50+
{
51+
52+
}
53+
}

tests/Command/FunctionalTest.php

Lines changed: 72 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use PHPUnit\Framework\TestCase;
66
use Symfony\Bundle\MakerBundle\Command\AbstractCommand;
7+
use Symfony\Bundle\MakerBundle\Command\MakeAuthenticatorCommand;
78
use Symfony\Bundle\MakerBundle\Command\MakeCommandCommand;
89
use Symfony\Bundle\MakerBundle\Command\MakeControllerCommand;
910
use Symfony\Bundle\MakerBundle\Command\MakeEntityCommand;
@@ -48,7 +49,7 @@ public function tearDown()
4849
*/
4950
public function testCommands(AbstractCommand $command, array $inputs)
5051
{
51-
/** @var AbstractCommand $command */
52+
/* @var AbstractCommand $command */
5253
$command->setCheckDependencies(false);
5354
$command->setGenerator($this->createGenerator());
5455

@@ -71,128 +72,136 @@ public function testCommands(AbstractCommand $command, array $inputs)
7172
public function getCommandTests()
7273
{
7374
$generator = $this->createGenerator();
74-
$commands = [];
75+
$commands = array();
7576

76-
$commands['command'] = [
77+
$commands['command'] = array(
7778
new MakeCommandCommand($generator),
78-
[
79+
array(
7980
// command name
80-
'app:foo'
81-
]
82-
];
81+
'app:foo',
82+
),
83+
);
8384

8485
$router = $this->createMock(RouterInterface::class);
8586
$router->expects($this->once())
8687
->method('getRouteCollection')
8788
->willReturn(new RouteCollection());
88-
$commands['controller'] = [
89+
$commands['controller'] = array(
8990
new MakeControllerCommand($generator, $router),
90-
[
91+
array(
9192
// controller class name
92-
'FooBar'
93-
]
94-
];
93+
'FooBar',
94+
),
95+
);
9596

96-
$commands['entity'] = [
97+
$commands['entity'] = array(
9798
new MakeEntityCommand($generator),
98-
[
99+
array(
99100
// entity class name
100-
'FooBar'
101-
]
102-
];
101+
'FooBar',
102+
),
103+
);
103104

104-
$commands['form'] = [
105+
$commands['form'] = array(
105106
new MakeFormCommand($generator),
106-
[
107+
array(
107108
// form name
108-
'FooBar'
109-
]
110-
];
109+
'FooBar',
110+
),
111+
);
111112

112-
$commands['functional'] = [
113+
$commands['functional'] = array(
113114
new MakeFunctionalTestCommand($generator),
114-
[
115+
array(
115116
// functional test class
116-
'FooBar'
117-
]
118-
];
117+
'FooBar',
118+
),
119+
);
119120

120121
$eventRegistry = $this->createMock(EventRegistry::class);
121122
$eventRegistry->expects($this->any())
122123
->method('getAllActiveEvents')
123-
->willReturn(['foo.bar']);
124+
->willReturn(array('foo.bar'));
124125
$eventRegistry->expects($this->once())
125126
->method('getEventClassName')
126127
->with('kernel.request')
127128
->willReturn(GetResponseEvent::class);
128-
$commands['subscriber'] = [
129+
$commands['subscriber'] = array(
129130
new MakeSubscriberCommand($generator, $eventRegistry),
130-
[
131+
array(
131132
// subscriber name
132133
'FooBar',
133134
// event name
134-
'kernel.request'
135-
],
136-
];
135+
'kernel.request',
136+
),
137+
);
137138

138139
$eventRegistry2 = $this->createMock(EventRegistry::class);
139140
$eventRegistry2->expects($this->any())
140141
->method('getAllActiveEvents')
141-
->willReturn([]);
142+
->willReturn(array());
142143
$eventRegistry2->expects($this->once())
143144
->method('getEventClassName')
144145
->willReturn(null);
145-
$commands['subscriber_unknown_event_class'] = [
146+
$commands['subscriber_unknown_event_class'] = array(
146147
new MakeSubscriberCommand($generator, $eventRegistry2),
147-
[
148+
array(
148149
// subscriber name
149150
'FooBar',
150151
// event name
151-
'foo.unknown_event'
152-
],
153-
];
152+
'foo.unknown_event',
153+
),
154+
);
154155

155-
$commands['serializer_encoder'] = [
156+
$commands['serializer_encoder'] = array(
156157
new MakeSerializerEncoderCommand($generator),
157158
[
158159
// encoder class name
159160
'FooBarEncoder',
160161
// encoder format
161162
'foobar'
162163
]
163-
];
164+
);
164165

165-
$commands['twig_extension'] = [
166+
$commands['twig_extension'] = array(
166167
new MakeTwigExtensionCommand($generator),
167-
[
168+
array(
168169
// extension class name
169-
'FooBar'
170-
]
171-
];
170+
'FooBar',
171+
),
172+
);
172173

173-
$commands['unit_test'] = [
174+
$commands['unit_test'] = array(
174175
new MakeUnitTestCommand($generator),
175-
[
176+
array(
176177
// class name
177-
'FooBar'
178-
]
179-
];
178+
'FooBar',
179+
),
180+
);
180181

181-
$commands['validator'] = [
182+
$commands['validator'] = array(
182183
new MakeValidatorCommand($generator),
183-
[
184+
array(
184185
// validator name
185-
'FooBar'
186-
]
187-
];
186+
'FooBar',
187+
),
188+
);
188189

189-
$commands['voter'] = [
190+
$commands['voter'] = array(
190191
new MakeVoterCommand($generator),
191-
[
192+
array(
192193
// voter class name
193-
'FooBar'
194-
]
195-
];
194+
'FooBar',
195+
),
196+
);
197+
198+
$commands['auth_empty'] = array(
199+
new MakeAuthenticatorCommand($generator),
200+
array(
201+
// class name
202+
'AppCustomAuthenticator',
203+
),
204+
);
196205

197206
return $commands;
198207
}
@@ -204,13 +213,13 @@ private function createGenerator()
204213

205214
private function parsePHPFiles($output)
206215
{
207-
$files = [];
216+
$files = array();
208217
foreach (explode("\n", $output) as $line) {
209218
if (false === strpos($line, 'created:')) {
210219
continue;
211220
}
212221

213-
[, $filename] = explode(':', $line);
222+
list(, $filename) = explode(':', $line);
214223
$files[] = trim($filename);
215224
}
216225

0 commit comments

Comments
 (0)