/** * Transfer the file to another adapter * * Note that you will receive a different file object depending on whether you're sending to a * local or remote file adapter. This will not be the same file object you passed in. You will * have 2 independent objects. * * @param MediaInterface $file The file * @param GaufretteAdapterInterface $adapter A gaufrette adapter * @param string $key File key (name) used in place of the file being transferred. Useful for overriding the default * @return LocalFileInterface|RemoteFileInterface The file object returned depends on the type of gaufrette adapter you're transferring to. * @throws UnknownTransferAdapterException When adapter is not a local or remote adapter */ public function transfer(MediaInterface $file, GaufretteAdapterInterface $adapter, $key = null) { if ($adapter instanceof LocalFileAdapterInterface) { $local = new LocalFile($key ?: $file->getKey(), $adapter); $local->write($file->read()); $local = $this->convertFile($local); return $local; } elseif ($adapter instanceof RemoteFileAdapterInterface) { $remote = new RemoteFile($key ?: $file->getKey(), $adapter); $remote->write($file->read()); return $remote; } else { throw new UnknownTransferAdapterException('Adapter must be a local or remote file adapter to transfer to.'); } }
public function testRenameUnsuccessful() { $key = 'foo'; $adapter = Mockery::mock(self::$fileAdapterInterface); $sut = new LocalFile($key, $adapter); $adapter->shouldReceive('rename')->with('foo', 'bar')->andReturn(false); $this->assertEquals(false, $sut->rename('bar')); }
public function __construct($key, LocalFileAdapterInterface $adapter, ImagineInterface $imagine) { $this->imagine = $imagine; parent::__construct($key, $adapter); }