Skip to content

Commit cf9496e

Browse files
committed
[Toolkit] Do not use FileSystem::readFile(), as it has been implemented in Symfony 7.1 and we want to support at least Symfony 6.4
1 parent 98b6005 commit cf9496e

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

src/Toolkit/src/Kit/KitFactory.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function createKitFromAbsolutePath(string $absolutePath): Kit
4545
throw new \InvalidArgumentException(\sprintf('File "%s" not found.', $manifestPath));
4646
}
4747

48-
$manifest = json_decode($this->filesystem->readFile($manifestPath), true, flags: \JSON_THROW_ON_ERROR);
48+
$manifest = json_decode(file_get_contents($manifestPath), true, flags: \JSON_THROW_ON_ERROR);
4949

5050
$kit = new Kit(
5151
path: $absolutePath,

src/Toolkit/src/Kit/KitSynchronizer.php

+7-3
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,11 @@ private function resolveComponentDependencies(Kit $kit, Component $component): v
101101

102102
// Find dependencies based on file content
103103
foreach ($component->files as $file) {
104-
$fileContent = $this->filesystem->readFile(Path::join($kit->path, $file->relativePathNameToKit));
104+
if (!$this->filesystem->exists($filePath = Path::join($kit->path, $file->relativePathNameToKit))) {
105+
throw new \RuntimeException(\sprintf('File "%s" not found', $filePath));
106+
}
107+
108+
$fileContent = file_get_contents($filePath);
105109

106110
if (FileType::Twig === $file->type) {
107111
if (str_contains($fileContent, 'html_cva')) {
@@ -174,14 +178,14 @@ private function synchronizeDocumentation(Kit $kit): void
174178
// Read INSTALL.md if exists
175179
$fileInstall = Path::join($kit->path, 'INSTALL.md');
176180
if ($this->filesystem->exists($fileInstall)) {
177-
$kit->installAsMarkdown = $this->filesystem->readFile($fileInstall);
181+
$kit->installAsMarkdown = file_get_contents($fileInstall);
178182
}
179183

180184
// Iterate over Component and find their documentation
181185
foreach ($kit->getComponents() as $component) {
182186
$docPath = Path::join($kit->path, 'docs', 'components', $component->name.'.md');
183187
if ($this->filesystem->exists($docPath)) {
184-
$component->doc = new Doc($this->filesystem->readFile($docPath));
188+
$component->doc = new Doc(file_get_contents($docPath));
185189
}
186190
}
187191
}

src/Toolkit/tests/Installer/InstallerTest.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public function testCanInstallComponent(): void
4646
$componentInstaller->installComponent($kit, $component, $this->tmpDir, false);
4747

4848
$this->assertFileExists($this->tmpDir.'/Button.html.twig');
49-
$this->assertSame($this->filesystem->readFile($this->tmpDir.'/Button.html.twig'), $this->filesystem->readFile(\sprintf('%s/templates/components/Button.html.twig', $kit->path)));
49+
$this->assertSame(file_get_contents($this->tmpDir.'/Button.html.twig'), file_get_contents(\sprintf('%s/templates/components/Button.html.twig', $kit->path)));
5050
}
5151

5252
public function testShouldAskIfFileAlreadyExists(): void
@@ -66,7 +66,7 @@ public function testShouldAskIfFileAlreadyExists(): void
6666

6767
$this->assertSame(0, $askedCount);
6868
$this->assertFileExists($this->tmpDir.'/Button.html.twig');
69-
$this->assertSame($this->filesystem->readFile($this->tmpDir.'/Button.html.twig'), $this->filesystem->readFile(\sprintf('%s/templates/components/Button.html.twig', $kit->path)));
69+
$this->assertSame(file_get_contents($this->tmpDir.'/Button.html.twig'), file_get_contents(\sprintf('%s/templates/components/Button.html.twig', $kit->path)));
7070

7171
$componentInstaller->installComponent($kit, $component, $this->tmpDir, false);
7272
$this->assertSame(1, $askedCount);
@@ -83,12 +83,12 @@ public function testCanInstallComponentIfForced(): void
8383
$componentInstaller->installComponent($kit, $component, $this->tmpDir, false);
8484

8585
$this->assertFileExists($this->tmpDir.'/Button.html.twig');
86-
$this->assertSame($this->filesystem->readFile($this->tmpDir.'/Button.html.twig'), $this->filesystem->readFile(\sprintf('%s/templates/components/Button.html.twig', $kit->path)));
86+
$this->assertSame(file_get_contents($this->tmpDir.'/Button.html.twig'), file_get_contents(\sprintf('%s/templates/components/Button.html.twig', $kit->path)));
8787

8888
$componentInstaller->installComponent($kit, $component, $this->tmpDir, true);
8989

9090
$this->assertFileExists($this->tmpDir.'/Button.html.twig');
91-
$this->assertSame($this->filesystem->readFile($this->tmpDir.'/Button.html.twig'), $this->filesystem->readFile(\sprintf('%s/templates/components/Button.html.twig', $kit->path)));
91+
$this->assertSame(file_get_contents($this->tmpDir.'/Button.html.twig'), file_get_contents(\sprintf('%s/templates/components/Button.html.twig', $kit->path)));
9292
}
9393

9494
public function testCanInstallComponentAndItsComponentDependencies(): void
@@ -119,7 +119,7 @@ public function testCanInstallComponentAndItsComponentDependencies(): void
119119

120120
foreach ($expectedFiles as $fileName => $expectedFile) {
121121
$this->assertFileExists($expectedFile);
122-
$this->assertSame($this->filesystem->readFile($expectedFile), $this->filesystem->readFile(\sprintf('%s/templates/components/%s', $kit->path, $fileName)));
122+
$this->assertSame(file_get_contents($expectedFile), file_get_contents(\sprintf('%s/templates/components/%s', $kit->path, $fileName)));
123123
}
124124
}
125125

0 commit comments

Comments
 (0)