X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;ds=sidebyside;f=vendor%2Falchemy%2Fzippy%2Fsrc%2FResource%2FTeleporter%2FLocalTeleporter.php;fp=vendor%2Falchemy%2Fzippy%2Fsrc%2FResource%2FTeleporter%2FLocalTeleporter.php;h=2e3c5df7d9a9e48af566a58d92c28642bbac0629;hb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;hp=0000000000000000000000000000000000000000;hpb=57c063afa3f66b07c4bbddc2d6129a96d90f0aad;p=yaffs-website diff --git a/vendor/alchemy/zippy/src/Resource/Teleporter/LocalTeleporter.php b/vendor/alchemy/zippy/src/Resource/Teleporter/LocalTeleporter.php new file mode 100644 index 000000000..2e3c5df7d --- /dev/null +++ b/vendor/alchemy/zippy/src/Resource/Teleporter/LocalTeleporter.php @@ -0,0 +1,82 @@ + + * + * 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\InvalidArgumentException; +use Alchemy\Zippy\Exception\IOException; +use Alchemy\Zippy\Resource\Resource as ZippyResource; +use Alchemy\Zippy\Resource\ResourceLocator; +use Symfony\Component\Filesystem\Exception\IOException as SfIOException; +use Symfony\Component\Filesystem\Filesystem; + +/** + * This class transports an object using the local filesystem + */ +class LocalTeleporter extends AbstractTeleporter +{ + /** + * @var Filesystem + */ + private $filesystem; + + /** + * @var ResourceLocator + */ + private $resourceLocator; + + /** + * Constructor + * + * @param Filesystem $filesystem + */ + public function __construct(Filesystem $filesystem) + { + $this->filesystem = $filesystem; + $this->resourceLocator = new ResourceLocator(); + } + + /** + * {@inheritdoc} + */ + public function teleport(ZippyResource $resource, $context) + { + $target = $this->resourceLocator->mapResourcePath($resource, $context); + $path = $resource->getOriginal(); + + if (!file_exists($path)) { + throw new InvalidArgumentException(sprintf('Invalid path %s', $path)); + } + + try { + if (is_file($path)) { + $this->filesystem->copy($path, $target); + } elseif (is_dir($path)) { + $this->filesystem->mirror($path, $target); + } else { + throw new InvalidArgumentException(sprintf('Invalid file or directory %s', $path)); + } + } catch (SfIOException $e) { + throw new IOException(sprintf('Could not write %s', $target), $e->getCode(), $e); + } + } + + /** + * Creates the LocalTeleporter + * + * @return LocalTeleporter + * @deprecated This method will be removed in a future release (0.5.x) + */ + public static function create() + { + return new static(new Filesystem()); + } +}