Skip to content

Commit 01e09c5

Browse files
committed
changes from review
1 parent 73844e3 commit 01e09c5

File tree

18 files changed

+99
-64
lines changed

18 files changed

+99
-64
lines changed

src/JsPackageManager.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@ public function __construct(FileManager $fileManager)
2828
$this->files = $fileManager;
2929
}
3030

31+
public function isInstalled(string $package): bool
32+
{
33+
$packageJson = $this->packageJson();
34+
$deps = \array_merge($packageJson['dependencies'] ?? [], $packageJson['devDependencies'] ?? []);
35+
36+
return \array_key_exists($package, $deps);
37+
}
38+
3139
public function add(string $package, string $version): void
3240
{
3341
$packageWithVersion = "{$package}@{$version}";
@@ -77,7 +85,7 @@ private function bin(): string
7785

7886
private function addToPackageJson(string $package, string $version): void
7987
{
80-
$packageJson = json_decode($this->files->getFileContents('package.json'), true);
88+
$packageJson = $this->packageJson();
8189
$devDeps = $packageJson['devDependencies'] ?? [];
8290
$devDeps[$package] = $version;
8391

@@ -87,4 +95,9 @@ private function addToPackageJson(string $package, string $version): void
8795

8896
$this->files->dumpFile('package.json', json_encode($packageJson, \JSON_PRETTY_PRINT | \JSON_UNESCAPED_SLASHES));
8997
}
98+
99+
private function packageJson(): array
100+
{
101+
return json_decode($this->files->getFileContents('package.json'), true);
102+
}
90103
}

src/Maker/MakeScaffold.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
*/
3232
final class MakeScaffold extends AbstractMaker
3333
{
34-
private $files;
34+
private $fileManager;
3535
private $jsPackageManager;
3636
private $availableScaffolds;
3737
private $composerBin;
@@ -41,7 +41,7 @@ final class MakeScaffold extends AbstractMaker
4141

4242
public function __construct(FileManager $files)
4343
{
44-
$this->files = $files;
44+
$this->fileManager = $files;
4545
$this->jsPackageManager = new JsPackageManager($files);
4646
}
4747

@@ -133,7 +133,7 @@ private function generateScaffold(string $name, ConsoleStyle $io): void
133133
$io->text("Installing Composer package: <comment>{$package}</comment>...");
134134

135135
$command = [$this->composerBin(), 'require', '--no-scripts', 'dev' === $env ? '--dev' : null, $package];
136-
$process = new Process(array_filter($command), $this->files->getRootDirectory());
136+
$process = new Process(array_filter($command), $this->fileManager->getRootDirectory());
137137

138138
$process->run();
139139

@@ -147,7 +147,7 @@ private function generateScaffold(string $name, ConsoleStyle $io): void
147147

148148
// install required js packages
149149
foreach ($scaffold['js_packages'] ?? [] as $package => $version) {
150-
if (!\in_array($package, $this->installedJsPackages, true)) {
150+
if (!$this->isJsPackageInstalled($package)) {
151151
$io->text("Installing JS package: <comment>{$package}@{$version}</comment>...");
152152

153153
$this->jsPackageManager->add($package, $version);
@@ -159,7 +159,7 @@ private function generateScaffold(string $name, ConsoleStyle $io): void
159159
$io->text('Copying scaffold files...');
160160

161161
foreach (Finder::create()->files()->in($scaffold['dir']) as $file) {
162-
$this->files->dumpFile(
162+
$this->fileManager->dumpFile(
163163
"{$file->getRelativePath()}/{$file->getFilenameWithoutExtension()}",
164164
$file->getContents()
165165
);
@@ -169,7 +169,7 @@ private function generateScaffold(string $name, ConsoleStyle $io): void
169169
if (isset($scaffold['configure'])) {
170170
$io->text('Executing configuration...');
171171

172-
$scaffold['configure']($this->files);
172+
$scaffold['configure']($this->fileManager);
173173
}
174174

175175
$io->text("Successfully installed scaffold <info>{$name}</info>.");
@@ -213,6 +213,11 @@ private function isPackageInstalled(string $package): bool
213213
return InstalledVersions::isInstalled($package) || \in_array($package, $this->installedPackages, true);
214214
}
215215

216+
private function isJsPackageInstalled(string $package): bool
217+
{
218+
return $this->jsPackageManager->isInstalled($package) || \in_array($package, $this->installedJsPackages, true);
219+
}
220+
216221
/**
217222
* Detect if package is installed in the same process (when installing
218223
* multiple scaffolds at once).

src/Resources/scaffolds/6.0/auth.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,6 @@
5555
],
5656
'remember_me' => [
5757
'secret' => '%kernel.secret%',
58-
'secure' => 'auto',
59-
'samesite' => 'lax',
6058
],
6159
];
6260

src/Resources/scaffolds/6.0/auth/src/Security/LoginUser.php.tpl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ use Symfony\Component\HttpFoundation\Request;
77
use Symfony\Component\Security\Http\Authentication\UserAuthenticatorInterface;
88
use Symfony\Component\Security\Http\Authenticator\AuthenticatorInterface;
99

10+
/**
11+
* Service to programatically login a user.
12+
*/
1013
class LoginUser
1114
{
1215
public function __construct(

src/Resources/scaffolds/6.0/change-password/src/Controller/ChangePasswordController.php.tpl

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ use Symfony\Component\HttpFoundation\Request;
1010
use Symfony\Component\HttpFoundation\Response;
1111
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
1212
use Symfony\Component\Routing\Annotation\Route;
13-
use Symfony\Component\Security\Core\User\UserInterface;
1413

1514
#[Route('/user/change-password', name: 'change_password')]
1615
class ChangePasswordController extends AbstractController
@@ -19,11 +18,10 @@ class ChangePasswordController extends AbstractController
1918
Request $request,
2019
UserPasswordHasherInterface $userPasswordHasher,
2120
UserRepository $userRepository,
22-
?UserInterface $user = null,
2321
): Response {
24-
if (!$user) {
25-
throw $this->createAccessDeniedException();
26-
}
22+
$this->denyAccessUnlessGranted('IS_AUTHENTICATED_REMEMBERED');
23+
24+
$user = $this->getUser();
2725
2826
if (!$user instanceof User) {
2927
throw new \LogicException('Invalid user type.');
@@ -41,14 +39,14 @@ class ChangePasswordController extends AbstractController
4139
)
4240
);
4341
44-
$userRepository->save($user);
42+
$userRepository->add($user);
4543
$this->addFlash('success', 'You\'ve successfully changed your password.');
4644
4745
return $this->redirectToRoute('homepage');
4846
}
4947

50-
return $this->render('user/change_password.html.twig', [
51-
'changePasswordForm' => $form->createView(),
48+
return $this->renderForm('user/change_password.html.twig', [
49+
'changePasswordForm' => $form,
5250
]);
5351
}
5452
}

src/Resources/scaffolds/6.0/change-password/src/Form/ChangePasswordFormType.php.tpl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,9 @@ class ChangePasswordFormType extends AbstractType
3737
'max' => 4096,
3838
]),
3939
],
40-
'label' => 'New password',
4140
],
4241
'second_options' => [
4342
'attr' => ['autocomplete' => 'new-password'],
44-
'label' => 'Repeat Password',
4543
],
4644
'invalid_message' => 'The password fields must match.',
4745
// Instead of being set onto the object directly,

src/Resources/scaffolds/6.0/change-password/tests/Functional/ChangePasswordTest.php.tpl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ final class ChangePasswordTest extends KernelTestCase
5858
->fillField('New Password', 'new-password')
5959
->fillField('Repeat New Password', 'new-password')
6060
->click('Change Password')
61-
->assertSuccessful()
61+
->assertStatus(422)
6262
->assertOn('/user/change-password')
6363
->assertSee('This is not your current password.')
6464
->assertAuthenticated('[email protected]')
@@ -78,7 +78,7 @@ final class ChangePasswordTest extends KernelTestCase
7878
->fillField('New Password', 'new-password')
7979
->fillField('Repeat New Password', 'new-password')
8080
->click('Change Password')
81-
->assertSuccessful()
81+
->assertStatus(422)
8282
->assertOn('/user/change-password')
8383
->assertSee('This is not your current password.')
8484
->assertAuthenticated('[email protected]')
@@ -97,7 +97,7 @@ final class ChangePasswordTest extends KernelTestCase
9797
->visit('/user/change-password')
9898
->fillField('Current Password', '1234')
9999
->click('Change Password')
100-
->assertSuccessful()
100+
->assertStatus(422)
101101
->assertOn('/user/change-password')
102102
->assertSee('Please enter a password.')
103103
->assertAuthenticated('[email protected]')
@@ -118,7 +118,7 @@ final class ChangePasswordTest extends KernelTestCase
118118
->fillField('New Password', 'new-password')
119119
->fillField('Repeat New Password', 'different-new-password')
120120
->click('Change Password')
121-
->assertSuccessful()
121+
->assertStatus(422)
122122
->assertOn('/user/change-password')
123123
->assertSee('The password fields must match.')
124124
->assertAuthenticated('[email protected]')

src/Resources/scaffolds/6.0/homepage/src/Controller/HomepageController.php.tpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
66
use Symfony\Component\HttpFoundation\Response;
77
use Symfony\Component\Routing\Annotation\Route;
88

9-
#[Route('/', name: 'homepage')]
109
class HomepageController extends AbstractController
1110
{
11+
#[Route('/', name: 'homepage')]
1212
public function __invoke(): Response
1313
{
14-
return $this->render('index.html.twig');
14+
return $this->render('homepage.html.twig');
1515
}
1616
}

src/Resources/scaffolds/6.0/profile/src/Controller/ProfileController.php.tpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class ProfileController extends AbstractController
2828
$form->handleRequest($request);
2929

3030
if ($form->isSubmitted() && $form->isValid()) {
31-
$userRepository->save($user);
31+
$userRepository->add($user);
3232
$this->addFlash('success', 'You\'ve successfully updated your profile.');
3333
3434
return $this->redirectToRoute('homepage');

0 commit comments

Comments
 (0)