Skip to content

Commit 743b535

Browse files
committed
#104106 Add ensure dir before file create
1 parent 5ffd96a commit 743b535

File tree

6 files changed

+12
-5
lines changed

6 files changed

+12
-5
lines changed

src/Generators/BaseGenerator.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,13 @@ protected function prepareDestinationDir(string $toDir): void
9696
$this->filesystem->cleanDirectory($toDir);
9797
}
9898

99+
protected function putWithDirectoryCheck(string $path, string $contents): int|bool
100+
{
101+
$this->filesystem->ensureDirectoryExists(dirname($path));
102+
103+
return $this->filesystem->put($path, $contents);
104+
}
105+
99106
private function formattedGlobalParams(): array
100107
{
101108
$params = [];

src/Generators/ControllersGenerator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public function {$methodName}({$paramsString})
116116
}
117117
$methodsString = trim($methodsString, "\n");
118118

119-
$this->filesystem->put(
119+
$this->putWithDirectoryCheck(
120120
$filePath,
121121
$this->replacePlaceholders($template, [
122122
'{{ namespace }}' => $namespace,

src/Generators/PoliciesGenerator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ protected function createPoliciesFiles(array $policies, string $template): void
7373
continue;
7474
}
7575

76-
$this->filesystem->put(
76+
$this->putWithDirectoryCheck(
7777
$filePath,
7878
$this->replacePlaceholders($template, [
7979
'{{ namespace }}' => $namespace,

src/Generators/RequestsGenerator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ protected function createRequestsFiles(array $requests, string $template): void
9797
continue;
9898
}
9999

100-
$this->filesystem->put(
100+
$this->putWithDirectoryCheck(
101101
$filePath,
102102
$this->replacePlaceholders(
103103
$template,

src/Generators/ResourcesGenerator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ protected function createResourcesFiles(array $resources, string $template): voi
106106
continue;
107107
}
108108

109-
$this->filesystem->put(
109+
$this->putWithDirectoryCheck(
110110
$filePath,
111111
$this->replacePlaceholders($template, [
112112
'{{ namespace }}' => $namespace,

src/Generators/TestsGenerator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ protected function createTestsFiles(array $testsData, string $template, $servers
9898
continue;
9999
}
100100

101-
$this->filesystem->put(
101+
$this->putWithDirectoryCheck(
102102
$filePath,
103103
$this->replacePlaceholders($template, [
104104
'{{ namespace }}' => $namespace,

0 commit comments

Comments
 (0)