Skip to content

Commit 1290144

Browse files
committed
[Filesystem] Add the readFile() method
1 parent 6f67094 commit 1290144

File tree

6 files changed

+13
-10
lines changed

6 files changed

+13
-10
lines changed

Command/AssetsInstallCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ private function getPublicDirectory(ContainerInterface $container): string
260260
return $defaultPublicDir;
261261
}
262262

263-
$composerConfig = json_decode(file_get_contents($composerFilePath), true);
263+
$composerConfig = json_decode($this->filesystem->readFile($composerFilePath), true, flags: \JSON_THROW_ON_ERROR);
264264

265265
return $composerConfig['extra']['public-dir'] ?? $defaultPublicDir;
266266
}

Command/CacheClearCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ private function warmup(string $warmupDir, string $realBuildDir): void
232232
$search = [$warmupDir, str_replace('\\', '\\\\', $warmupDir)];
233233
$replace = str_replace('\\', '/', $realBuildDir);
234234
foreach (Finder::create()->files()->in($warmupDir) as $file) {
235-
$content = str_replace($search, $replace, file_get_contents($file), $count);
235+
$content = str_replace($search, $replace, $this->filesystem->readFile($file), $count);
236236
if ($count) {
237237
file_put_contents($file, $content);
238238
}

DependencyInjection/FrameworkExtension.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
use Symfony\Component\EventDispatcher\Attribute\AsEventListener;
7272
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
7373
use Symfony\Component\ExpressionLanguage\ExpressionLanguage;
74+
use Symfony\Component\Filesystem\Filesystem;
7475
use Symfony\Component\Finder\Finder;
7576
use Symfony\Component\Finder\Glob;
7677
use Symfony\Component\Form\Extension\HtmlSanitizer\Type\TextTypeHtmlSanitizerExtension;
@@ -3141,7 +3142,7 @@ private function getPublicDirectory(ContainerBuilder $container): string
31413142
}
31423143

31433144
$container->addResource(new FileResource($composerFilePath));
3144-
$composerConfig = json_decode(file_get_contents($composerFilePath), true);
3145+
$composerConfig = json_decode((new Filesystem())->readFile($composerFilePath), true, flags: \JSON_THROW_ON_ERROR);
31453146

31463147
return isset($composerConfig['extra']['public-dir']) ? $projectDir.'/'.$composerConfig['extra']['public-dir'] : $defaultPublicDir;
31473148
}

Tests/Command/CacheClearCommand/CacheClearCommandTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ function () use ($file) {
7575
$kernelRef = new \ReflectionObject($this->kernel);
7676
$kernelFile = $kernelRef->getFileName();
7777
/** @var ResourceInterface[] $meta */
78-
$meta = unserialize(file_get_contents($containerMetaFile));
78+
$meta = unserialize($this->fs->readFile($containerMetaFile));
7979
$found = false;
8080
foreach ($meta as $resource) {
8181
if ((string) $resource === $kernelFile) {
@@ -93,7 +93,7 @@ function () use ($file) {
9393
);
9494
$this->assertMatchesRegularExpression(
9595
sprintf('/\'kernel.container_class\'\s*=>\s*\'%s\'/', $containerClass),
96-
file_get_contents($containerFile),
96+
$this->fs->readFile($containerFile),
9797
'kernel.container_class is properly set on the dumped container'
9898
);
9999
}

Tests/Secrets/SodiumVaultTest.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,18 @@
2121
class SodiumVaultTest extends TestCase
2222
{
2323
private string $secretsDir;
24+
private Filesystem $filesystem;
2425

2526
protected function setUp(): void
2627
{
28+
$this->filesystem = new Filesystem();
2729
$this->secretsDir = sys_get_temp_dir().'/sf_secrets/test/';
28-
(new Filesystem())->remove($this->secretsDir);
30+
$this->filesystem->remove($this->secretsDir);
2931
}
3032

3133
protected function tearDown(): void
3234
{
33-
(new Filesystem())->remove($this->secretsDir);
35+
$this->filesystem->remove($this->secretsDir);
3436
}
3537

3638
public function testGenerateKeys()
@@ -41,8 +43,8 @@ public function testGenerateKeys()
4143
$this->assertFileExists($this->secretsDir.'/test.encrypt.public.php');
4244
$this->assertFileExists($this->secretsDir.'/test.decrypt.private.php');
4345

44-
$encKey = file_get_contents($this->secretsDir.'/test.encrypt.public.php');
45-
$decKey = file_get_contents($this->secretsDir.'/test.decrypt.private.php');
46+
$encKey = $this->filesystem->readFile($this->secretsDir.'/test.encrypt.public.php');
47+
$decKey = $this->filesystem->readFile($this->secretsDir.'/test.decrypt.private.php');
4648

4749
$this->assertFalse($vault->generateKeys());
4850
$this->assertStringEqualsFile($this->secretsDir.'/test.encrypt.public.php', $encKey);

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"symfony/http-foundation": "^6.4|^7.0",
2929
"symfony/http-kernel": "^6.4|^7.0",
3030
"symfony/polyfill-mbstring": "~1.0",
31-
"symfony/filesystem": "^6.4|^7.0",
31+
"symfony/filesystem": "^7.1",
3232
"symfony/finder": "^6.4|^7.0",
3333
"symfony/routing": "^6.4|^7.0"
3434
},

0 commit comments

Comments
 (0)