X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=vendor%2Falchemy%2Fzippy%2Fsrc%2FResource%2FTeleporter%2FAbstractTeleporter.php;fp=vendor%2Falchemy%2Fzippy%2Fsrc%2FResource%2FTeleporter%2FAbstractTeleporter.php;h=401aed8d1f5aeb641fcfc7456cee02033aa2f4a5;hp=0000000000000000000000000000000000000000;hb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;hpb=57c063afa3f66b07c4bbddc2d6129a96d90f0aad diff --git a/vendor/alchemy/zippy/src/Resource/Teleporter/AbstractTeleporter.php b/vendor/alchemy/zippy/src/Resource/Teleporter/AbstractTeleporter.php new file mode 100644 index 000000000..401aed8d1 --- /dev/null +++ b/vendor/alchemy/zippy/src/Resource/Teleporter/AbstractTeleporter.php @@ -0,0 +1,64 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Alchemy\Zippy\Resource\Teleporter; + +use Alchemy\Zippy\Exception\IOException; +use Alchemy\Zippy\Resource\Resource as ZippyResource; + +/** + * Class AbstractTeleporter + * @package Alchemy\Zippy\Resource\Teleporter + * + * @deprecated Typehint against TeleporterInterface instead and use GenericTeleporter +* with custom reader/writers instead. This class will be removed in v0.5.x + */ +abstract class AbstractTeleporter implements TeleporterInterface +{ + /** + * Writes the target + * + * @param string $data + * @param ZippyResource $resource + * @param string $context + * + * @return TeleporterInterface + * + * @throws IOException + */ + protected function writeTarget($data, ZippyResource $resource, $context) + { + $target = $this->getTarget($context, $resource); + + if (!file_exists(dirname($target)) && false === mkdir(dirname($target))) { + throw new IOException(sprintf('Could not create parent directory %s', dirname($target))); + } + + if (false === file_put_contents($target, $data)) { + throw new IOException(sprintf('Could not write to %s', $target)); + } + + return $this; + } + + /** + * Returns the relative target of a Resource + * + * @param string $context + * @param ZippyResource $resource + * + * @return string + */ + protected function getTarget($context, ZippyResource $resource) + { + return sprintf('%s/%s', rtrim($context, '/'), $resource->getTarget()); + } +}