Skip to content

Commit a788a55

Browse files
author
Thibaud Fabre
committed
Explicitely create parent directory of target files
- Close #93
1 parent b73ba0c commit a788a55

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/Resource/Teleporter/AbstractTeleporter.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ abstract class AbstractTeleporter implements TeleporterInterface
1919
/**
2020
* Writes the target
2121
*
22-
* @param String $data
23-
* @param Resource $resource
24-
* @param String $context
22+
* @param string $data
23+
* @param \Alchemy\Zippy\Resource\Resource $resource
24+
* @param string $context
2525
*
2626
* @return TeleporterInterface
2727
*
@@ -31,6 +31,10 @@ protected function writeTarget($data, Resource $resource, $context)
3131
{
3232
$target = $this->getTarget($context, $resource);
3333

34+
if (! file_exists(dirname($target)) && false === mkdir(dirname($target))) {
35+
throw new IOException(sprintf('Could not create parent directory %s', dirname($target)));
36+
}
37+
3438
if (false === file_put_contents($target, $data)) {
3539
throw new IOException(sprintf('Could not write to %s', $target));
3640
}

0 commit comments

Comments
 (0)