Skip to content

Commit

Permalink
Add more detailed exception messages for NotWritableException
Browse files Browse the repository at this point in the history
  • Loading branch information
olivervogel committed Dec 23, 2023
1 parent 03aa19c commit b58b4b0
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,21 @@ public function __construct(protected string $data)
*/
public function save(string $filepath): void
{
$dir = pathinfo($filepath, PATHINFO_DIRNAME);

if (!is_dir($dir)) {
throw new NotWritableException(
"Can't write image to path. Directory does not exist."
);
}

if (!is_writable($dir)) {
throw new NotWritableException(
"Can't write image to path. Directory is not writable."
);
}

// write date
$saved = @file_put_contents($filepath, (string) $this);
if ($saved === false) {
throw new NotWritableException(
Expand Down

0 comments on commit b58b4b0

Please sign in to comment.