| @@ 84-107 (lines=24) @@ | ||
| 81 | * @param string $targetPath |
|
| 82 | * @param string $fileContent |
|
| 83 | */ |
|
| 84 | public function writeFile ($targetPath, $fileContent) |
|
| 85 | { |
|
| 86 | $outputFolder = $this->fs->getFolderPath($targetPath); |
|
| 87 | $targetFileName = $this->fs->getFileName($outputFolder); |
|
| 88 | ||
| 89 | $absoluteFolderPath = $this->buildPath($this->getCwd(), $outputFolder); |
|
| 90 | ||
| 91 | if (!file_exists($absoluteFolderPath)) |
|
| 92 | { |
|
| 93 | mkdir($absoluteFolderPath, 0755, true); |
|
| 94 | } |
|
| 95 | ||
| 96 | file_put_contents( |
|
| 97 | $this->buildPath($this->getCwd(), $targetPath), |
|
| 98 | $fileContent, |
|
| 99 | LOCK_EX |
|
| 100 | ); |
|
| 101 | ||
| 102 | return (new SplFileInfo( |
|
| 103 | $targetFileName, |
|
| 104 | $absoluteFolderPath, |
|
| 105 | $this->buildPath($absoluteFolderPath, $targetFileName) |
|
| 106 | )); |
|
| 107 | } |
|
| 108 | ||
| 109 | /** |
|
| 110 | * @param string $pathFragments |
|
| @@ 208-225 (lines=18) @@ | ||
| 205 | * |
|
| 206 | * @return SplFileInfo A reference to the newly created file |
|
| 207 | */ |
|
| 208 | public function writeFile ($targetDir, $fileName, $content) |
|
| 209 | { |
|
| 210 | $outputFolder = $this->getFolderPath($this->absolutePath($targetDir, $fileName)); |
|
| 211 | $targetFile = $this->getFileName($fileName); |
|
| 212 | ||
| 213 | if (!file_exists($outputFolder)) |
|
| 214 | { |
|
| 215 | mkdir($outputFolder, 0755, true); |
|
| 216 | } |
|
| 217 | ||
| 218 | file_put_contents($this->appendPath($outputFolder, $targetFile), $content, LOCK_EX); |
|
| 219 | ||
| 220 | return (new SplFileInfo( |
|
| 221 | $fileName, |
|
| 222 | $this->absolutePath($targetDir), |
|
| 223 | $this->absolutePath($targetDir, $fileName)) |
|
| 224 | ); |
|
| 225 | } |
|
| 226 | } |
|