1
0
Fork 0

Make sure .composer dir is created before writing in it

pull/48/head
Jordi Boggiano 2011-10-02 20:46:33 +02:00
parent 61dc13647c
commit 18e28a2a9f
1 changed files with 13 additions and 0 deletions

View File

@ -64,6 +64,19 @@ class JsonFile
*/
public function write(array $hash)
{
$dir = dirname($this->path);
if (!is_dir($dir)) {
if (file_exists($dir)) {
throw new \UnexpectedValueException(
$dir.' exists and is not a directory.'
);
}
if (!mkdir($dir, 0777, true)) {
throw new \UnexpectedValueException(
$dir.' does not exist and could not be created.'
);
}
}
file_put_contents($this->path, json_encode($hash));
}