Skip to content

Commit ae12045

Browse files
committed
feature #266 Make login form (nikophil)
This PR was squashed before being merged into the 1.0-dev branch (closes #266). Discussion ---------- Make login form Improvements for the command `make:auth` in order to create a form login. Now, the `make:auth` command asks if the user wants an empty authenticator or a form login. If "form login" is chosen, the user is asked for the security controller name, and for the user class, if needed. If the controller already exists, the command adds the login / logout methods in the existing controller. Commits ------- 5257b67 form login : PR review : batch 5 cd86b3b form login : PR review : batch 4 78abbf4 form login : fix after review - batch 3 bc0089d form login : use dynamic username field 388df31 form login : guess if encoder is needed c44f878 fix after review - batch 1 9ec9766 Test logging process with users as entity fd76519 unit tests 7fd5a35 Add tests into fixtures files 02ff624 Functional tests f96c51e Add logout method to already existing SecurityController 0bfd028 Handle when securityController provided already exist 011b1d6 Merge MakeLoginForm into MakeAuthenticator efb19e4 create MakeFormLogin command
2 parents 24ae473 + 5257b67 commit ae12045

File tree

47 files changed

+2147
-66
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+2147
-66
lines changed

src/Doctrine/DoctrineHelper.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,4 +177,13 @@ public function createDoctrineDetails(string $entityClassName)
177177

178178
return null;
179179
}
180+
181+
public function isClassAMappedEntity(string $className): bool
182+
{
183+
if (!$this->isDoctrineInstalled()) {
184+
return false;
185+
}
186+
187+
return (bool) $this->getMetadata($className);
188+
}
180189
}

src/Generator.php

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Bundle\MakerBundle;
1313

14+
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
1415
use Symfony\Bundle\MakerBundle\Exception\RuntimeCommandException;
1516
use Symfony\Bundle\MakerBundle\Util\ClassNameDetails;
1617

@@ -84,6 +85,22 @@ public function dumpFile(string $targetPath, string $contents)
8485
];
8586
}
8687

88+
public function getFileContentsForPendingOperation(string $targetPath): string
89+
{
90+
if (!isset($this->pendingOperations[$targetPath])) {
91+
throw new RuntimeCommandException(sprintf('File "%s" is not in the Generator\'s pending operations', $targetPath));
92+
}
93+
94+
$templatePath = $this->pendingOperations[$targetPath]['template'];
95+
$parameters = $this->pendingOperations[$targetPath]['variables'];
96+
97+
$templateParameters = array_merge($parameters, [
98+
'relative_path' => $this->fileManager->relativizePath($targetPath),
99+
]);
100+
101+
return $this->fileManager->parseTemplate($templatePath, $templateParameters);
102+
}
103+
87104
/**
88105
* Creates a helper object to get data about a class name.
89106
*
@@ -178,15 +195,10 @@ public function writeChanges()
178195
continue;
179196
}
180197

181-
$templatePath = $templateData['template'];
182-
$parameters = $templateData['variables'];
183-
184-
$templateParameters = array_merge($parameters, [
185-
'relative_path' => $this->fileManager->relativizePath($targetPath),
186-
]);
187-
188-
$fileContents = $this->fileManager->parseTemplate($templatePath, $templateParameters);
189-
$this->fileManager->dumpFile($targetPath, $fileContents);
198+
$this->fileManager->dumpFile(
199+
$targetPath,
200+
$this->getFileContentsForPendingOperation($targetPath, $templateData)
201+
);
190202
}
191203

192204
$this->pendingOperations = [];
@@ -196,4 +208,16 @@ public function getRootNamespace(): string
196208
{
197209
return $this->namespacePrefix;
198210
}
211+
212+
public function generateController(string $controllerClassName, string $controllerTemplatePath, array $parameters = []): string
213+
{
214+
return $this->generateClass(
215+
$controllerClassName,
216+
$controllerTemplatePath,
217+
$parameters +
218+
[
219+
'parent_class_name' => \method_exists(AbstractController::class, 'getParameter') ? 'AbstractController' : 'Controller',
220+
]
221+
);
222+
}
199223
}

src/Maker/AbstractMaker.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Bundle\MakerBundle\Maker;
1313

1414
use Symfony\Bundle\MakerBundle\ConsoleStyle;
15+
use Symfony\Bundle\MakerBundle\DependencyBuilder;
1516
use Symfony\Bundle\MakerBundle\MakerInterface;
1617
use Symfony\Component\Console\Command\Command;
1718
use Symfony\Component\Console\Input\InputInterface;
@@ -33,4 +34,18 @@ protected function writeSuccessMessage(ConsoleStyle $io)
3334
$io->writeln(' <bg=green;fg=white> </>');
3435
$io->newLine();
3536
}
37+
38+
protected function addDependencies(array $dependencies, string $message = null): string
39+
{
40+
$dependencyBuilder = new DependencyBuilder();
41+
42+
foreach ($dependencies as $class => $name) {
43+
$dependencyBuilder->addClassDependency($class, $name);
44+
}
45+
46+
return $dependencyBuilder->getMissingPackagesMessage(
47+
$this->getCommandName(),
48+
$message
49+
);
50+
}
3651
}

0 commit comments

Comments
 (0)