Skip to content

Commit be191ce

Browse files
committed
iterate
1 parent 4a41bc3 commit be191ce

File tree

5 files changed

+18
-22
lines changed

5 files changed

+18
-22
lines changed

src/Toolkit/src/Command/InstallComponentCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
172172

173173
$this->io->success('The component has been installed.');
174174
$this->io->writeln('The following file(s) have been added to your project:');
175-
$this->io->listing(array_map(fn (File $file) => Path::join($destinationPath, $file->toRelativePathName), $installationReport->newFiles));
175+
$this->io->listing(array_map(fn (File $file) => Path::join($destinationPath, $file->sourceRelativePathName), $installationReport->newFiles));
176176

177177
if ([] !== $installationReport->suggestedPhpPackages) {
178178
$this->io->writeln(\sprintf('Run <info>composer require %s</> to install the required PHP dependencies.', implode(' ', $installationReport->suggestedPhpPackages)));

src/Toolkit/src/Installer/Installer.php

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515

1616
use Symfony\Component\Filesystem\Filesystem;
1717
use Symfony\Component\Filesystem\Path;
18-
use Symfony\UX\Toolkit\Asset\Component;
19-
use Symfony\UX\Toolkit\File\File;
2018
use Symfony\UX\Toolkit\Kit\Kit;
2119
use Symfony\UX\Toolkit\Recipe\Recipe;
2220

@@ -49,25 +47,22 @@ private function handlePool(Pool $pool, Kit $kit, string $destinationPath, bool
4947
{
5048
$installedFiles = [];
5149

52-
foreach ($pool->getFiles() as $file) {
53-
if ($this->installFile($kit, $file, $destinationPath, $force)) {
54-
$installedFiles[] = $file;
50+
foreach ($pool->getFiles() as $recipeAbsolutePath => $files) {
51+
foreach ($files as $file) {
52+
$sourceAbsolutePathName = Path::join($recipeAbsolutePath, $file->sourceRelativePathName);
53+
$destinationAbsolutePathName = Path::join($destinationPath, $file->destinationRelativePathName);
54+
55+
if ($this->copyFile($kit, $sourceAbsolutePathName, $destinationAbsolutePathName, $force)) {
56+
$installedFiles[] = $file;
57+
}
5558
}
5659
}
5760

5861
return new InstallationReport(newFiles: $installedFiles, suggestedPhpPackages: $pool->getPhpPackageDependencies());
5962
}
6063

61-
/**
62-
* @param non-empty-string $destinationPath
63-
*/
64-
private function installFile(Kit $kit, File $file, string $destinationPath, bool $force): bool
64+
private function copyFile(Kit $kit, string $sourceAbsolutePathName, string $destinationAbsolutePathName, bool $force): bool
6565
{
66-
$sourceAbsolutePathName = Path::join($kit->absolutePath, $file->sourceRelativePathName);
67-
$destinationAbsolutePathName = Path::join($destinationPath, $file->destinationRelativePathName);
68-
69-
dump(source: $sourceAbsolutePathName, destination: $destinationAbsolutePathName, force: $force);
70-
7166
if ($this->filesystem->exists($destinationAbsolutePathName) && !$force) {
7267
if (!($this->askConfirmation)(\sprintf('File "%s" already exists. Do you want to overwrite it?', $destinationAbsolutePathName))) {
7368
return false;

src/Toolkit/src/Installer/Pool.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
use Symfony\UX\Toolkit\Dependency\PhpPackageDependency;
1717
use Symfony\UX\Toolkit\File\File;
18+
use Symfony\UX\Toolkit\Recipe\Recipe;
1819

1920
/**
2021
* Represents a pool of files and dependencies to be installed.
@@ -35,13 +36,13 @@ final class Pool
3536
*/
3637
private array $phpPackageDependencies = [];
3738

38-
public function addFile(File $file): void
39+
public function addFile(Recipe $recipe, File $file): void
3940
{
40-
$this->files[$file->destinationRelativePathName] ??= $file;
41+
$this->files[$recipe->absolutePath][$file->destinationRelativePathName] ??= $file;
4142
}
4243

4344
/**
44-
* @return array<non-empty-string, File>
45+
* @return array<non-empty-string, array<non-empty-string, File>>
4546
*/
4647
public function getFiles(): array
4748
{

src/Toolkit/src/Installer/PoolResolver.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,15 @@ public function resolveForRecipe(Kit $kit, Recipe $recipe): Pool
3939
$visitedRecipes->attach($currentComponent);
4040

4141
foreach ($recipe->getFiles() as $file) {
42-
$pool->addFile($file);
42+
$pool->addFile($recipe, $file);
4343
}
4444

4545
foreach ($recipe->manifest->dependencies as $dependency) {
4646
if ($dependency instanceof PhpPackageDependency) {
4747
$pool->addPhpPackageDependency($dependency);
48-
} elseif($dependency instanceof RecipeDependency) {
48+
} elseif ($dependency instanceof RecipeDependency) {
4949
if (null === $recipeDependency = $kit->getRecipe($dependency->name)) {
50-
throw new \LogicException(sprintf('The recipe "%s" has a dependency on unregistered recipe "%s".', $recipe->manifest->name, $dependency->name));
50+
throw new \LogicException(\sprintf('The recipe "%s" has a dependency on unregistered recipe "%s".', $recipe->manifest->name, $dependency->name));
5151
}
5252

5353
$recipesStack[] = $recipeDependency;

src/Toolkit/src/Kit/Kit.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public function getRecipes(?RecipeType $type = null): array
6868
public function getRecipe(string $name, ?RecipeType $type = null): ?Recipe
6969
{
7070
foreach ($this->recipes as $recipe) {
71-
if ($recipe->manifest->name === $name && ($type === null || $recipe->manifest->type === $type)) {
71+
if ($recipe->manifest->name === $name && (null === $type || $recipe->manifest->type === $type)) {
7272
return $recipe;
7373
}
7474
}

0 commit comments

Comments
 (0)