Skip to content

Commit

Permalink
Merge pull request #39 from eclipxe13/master
Browse files Browse the repository at this point in the history
Create folder (recursively) for cache file if it does not exists
  • Loading branch information
overtrue authored Apr 5, 2018
2 parents e9d1e0c + f4e510f commit 24434a9
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,20 @@ public static function put($contents)
public static function setFilename($filename)
{
self::$filename = $filename;
self::makeFolderForFilename();
}

/**
* Try to create the folder recursively where the cache file is stored.
* It depends on current value of static::getFilename().
*/
private static function makeFolderForFilename()
{
$filename = self::getFilename();
$dirname = dirname($filename);
if (!file_exists($dirname)) {
mkdir($dirname, 0777, true);
}
}

/**
Expand Down

0 comments on commit 24434a9

Please sign in to comment.