Skip to content

Commit 2b5b82e

Browse files
chore(poc): retakes
1 parent 53a4143 commit 2b5b82e

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

src/Infrastructure/Adapter/DatexGenerator.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
use App\Application\QueryBusInterface;
99
use App\Application\Regulation\DatexGeneratorInterface;
1010
use App\Application\Regulation\Query\GetRegulationOrdersToDatexFormatQuery;
11+
use Symfony\Component\Filesystem\Filesystem;
12+
use Symfony\Component\Filesystem\Path;
1113

1214
final class DatexGenerator implements DatexGeneratorInterface
1315
{
@@ -17,9 +19,10 @@ public function __construct(
1719
private \Twig\Environment $twig,
1820
private DateUtilsInterface $dateUtils,
1921
private QueryBusInterface $queryBus,
22+
private Filesystem $filesystem,
2023
string $projectDir,
2124
) {
22-
$this->datexFilePath = $projectDir . '/var/datex/regulations.xml';
25+
$this->datexFilePath = Path::join($projectDir, '/var/datex/regulations.xml');
2326
}
2427

2528
public function generate(): void
@@ -28,10 +31,10 @@ public function generate(): void
2831
new GetRegulationOrdersToDatexFormatQuery(),
2932
);
3033

31-
$dir = \dirname($this->datexFilePath);
34+
$dir = Path::getDirectory($this->datexFilePath);
3235

33-
if (!is_dir($dir)) {
34-
mkdir($dir, 0o755, true);
36+
if (!$this->filesystem->exists($dir)) {
37+
$this->filesystem->mkdir($dir, 0o755);
3538
}
3639

3740
$tmpFile = $this->datexFilePath . '.tmp';
@@ -50,15 +53,15 @@ public function generate(): void
5053

5154
ob_end_flush();
5255
fclose($handle);
53-
rename($tmpFile, $this->datexFilePath);
56+
$this->filesystem->rename($tmpFile, $this->datexFilePath, overwrite: true);
5457
}
5558

5659
public function getCachedDatex(): string
5760
{
58-
if (!file_exists($this->datexFilePath)) {
61+
if (!$this->filesystem->exists($this->datexFilePath)) {
5962
$this->generate();
6063
}
6164

62-
return file_get_contents($this->datexFilePath);
65+
return $this->filesystem->readFile($this->datexFilePath);
6366
}
6467
}

0 commit comments

Comments
 (0)