Ejemplo n.º 1
0
 public function __construct(AdapterInterface $local, AdapterInterface $remote)
 {
     // Remember the local root path
     $this->localRootPath = $local->getPathPrefix();
     // Create the local filesystem
     $local = new Filesystem($local);
     $local->addPlugin(new ListWith());
     $this->localFilesystem = $local;
     // The remote filesystem
     $remote = new Filesystem($remote);
     // Create the manager with the local and remote filesystems
     $this->manager = new MountManager(compact('local', 'remote'));
 }
 /**
  * Get the URL using a `hasDir()` method on the adapter.
  *
  * @param  string $path
  * @return string
  */
 protected function getFromMethod($path)
 {
     $res = false;
     if ($this->cachedAdapter) {
         $res = $this->cachedAdapter->getMetadata($path);
     }
     if (!$res || !isset($res['hasdir'])) {
         $res = $this->adapter->hasDir($path);
     }
     if (is_array($res)) {
         return isset($res['hasdir']) ? $res['hasdir'] : true;
     } else {
         return $res;
     }
 }
 /**
  * Create the cache key.
  *
  * @param string $path The file path.
  *
  * @return string
  */
 private function getCacheKey($path)
 {
     if ($this->adapter instanceof ProvidesCacheKey) {
         return $this->adapter->getCacheKey($path);
     }
     return md5($path);
 }
Ejemplo n.º 4
0
 /**
  * {@inheritDoc}
  */
 public function getVisibility($pathOrUuid)
 {
     $path = $this->convertToPath($pathOrUuid);
     $this->guardNoInvalidUuid($pathOrUuid, $path);
     $this->guardInUploadPath($path);
     return $this->adapter->getVisibility($path);
 }
Ejemplo n.º 5
0
 /**
  * {@inheritdoc}
  */
 public function setVisibility($path, $visibility)
 {
     if (!$this->source->setVisibility($path, $visibility)) {
         return false;
     }
     return $this->replica->setVisibility($path, $visibility);
 }
 public function it_should_cache_contents_listings()
 {
     $this->cache->isComplete($dirname = 'dirname', $recursive = true)->willReturn(false);
     $response = [['path' => 'path.txt']];
     $this->adapter->listContents($dirname, $recursive)->willReturn($response);
     $this->cache->storeContents($dirname, $response, $recursive)->shouldBeCalled();
     $this->listContents($dirname, $recursive)->shouldBe($response);
 }
Ejemplo n.º 7
0
 /**
  * {@inheritdoc}
  */
 public function save()
 {
     $contents = $this->getForStorage();
     if ($this->adapter->has($this->file)) {
         $this->adapter->update($this->file, $contents);
     } else {
         $this->adapter->write($this->file, $contents);
     }
 }
Ejemplo n.º 8
0
 /**
  * {@inheritdoc}
  */
 public function listContents($directory = '', $recursive = false)
 {
     if ($this->cache->isComplete($directory, $recursive)) {
         return $this->cache->listContents($directory, $recursive);
     }
     $result = $this->adapter->listContents($directory, $recursive);
     if ($result) {
         $this->cache->storeContents($directory, $result, $recursive);
     }
     return $result;
 }
Ejemplo n.º 9
0
 /**
  * Get a file's metadata.
  *
  * @param string $path path to file
  *
  * @throws FileNotFoundException
  *
  * @return array|false file metadata or FALSE when fails
  *                     to fetch it from existing file
  */
 public function getMetadata($path)
 {
     $path = Util::normalizePath($path);
     $this->assertPresent($path);
     if ($metadata = $this->cache->getMetadata($path)) {
         return $metadata;
     }
     if (!($metadata = $this->adapter->getMetadata($path))) {
         return false;
     }
     return $this->cache->updateObject($path, $metadata, true);
 }
 /**
  * Copies a resource accessible through the fallback adapter to the filesystem abstracted with the main adapter.
  *
  * @param $path
  * @return boolean
  */
 private function portFromFallback($path, $newpath)
 {
     $buffer = $this->fallback->readStream($path);
     if (false === $buffer) {
         return false;
     }
     $result = $this->mainAdapter->writeStream($newpath, $buffer['stream'], new Config());
     if (is_resource($buffer['stream'])) {
         fclose($buffer['stream']);
     }
     return false !== $result;
 }
Ejemplo n.º 11
0
 /**
  * İstenilen bir yere yükleme yapar.
  *
  * @param string $yol
  * @return bool
  */
 public function yukle($yol)
 {
     // dosyaların yüklenmesi tamam mı?
     if (!$this->isYuklemeTamam()) {
         throw new \RuntimeException('Dosyaların yüklenmesi ile ilgili bir sorun var.');
     }
     // adaptör set edilmiş olmalı
     if (!$this->adapter instanceof AdapterInterface) {
         throw new \RuntimeException('Yükleme yapmak için adaptör tanımlanmamış.');
     }
     // dosyalar üzerinde dönelim
     foreach ($this->dosyaBilgileri as $dosyaBilgisi) {
         // dosyayı yükleyelim
         $this->adapter->write($yol, file_get_contents($dosyaBilgisi->getPathname()), new Config());
     }
     // başarılı bir dönüş yapalım
     return true;
 }
 /**
  * @inheritdoc
  */
 public function writeStream($path, $resource, Config $config)
 {
     return $this->adapter->writeStream($path, $resource, $config);
 }
Ejemplo n.º 13
0
 /**
  * {@inheritdoc}
  */
 public function getVisibility($path)
 {
     return $this->adapter->getVisibility($this->getPath($path));
 }
Ejemplo n.º 14
0
 /**
  * Get a file's metadata.
  *
  * @param string $path path to file
  *
  * @throws FileNotFoundException
  *
  * @return array|false file metadata or FALSE when fails
  *                     to fetch it from existing file
  */
 public function getMetadata($path)
 {
     $path = Util::normalizePath($path);
     $this->assertPresent($path);
     return $this->adapter->getMetadata($path);
 }
Ejemplo n.º 15
0
 function it_renames_file(AdapterInterface $adapter)
 {
     $adapter->rename('oldfilename', 'newfilename')->willReturn(true);
     $this->rename('oldfilename', 'newfilename')->shouldReturn(true);
 }
Ejemplo n.º 16
0
 /**
  * @param SftpAdapter $adapter
  *
  * @return string
  */
 protected function getLastError(AdapterInterface $adapter)
 {
     return $adapter->getConnection()->getLastSFTPError();
 }
Ejemplo n.º 17
0
 /**
  * Creates backend filesystem
  *
  * @param array               $backendConfig
  * @param AdapterInterface    $adapter
  * @param array|null          $filesystemConfig
  * @param CacheInterface|null $cache
  *
  * @return Backend
  */
 public function createBackend(array $backendConfig, AdapterInterface $adapter, array $filesystemConfig = null, CacheInterface $cache = null)
 {
     if ($adapter instanceof ContainerAwareInterface) {
         $adapter->setContainer($this->app);
     }
     if (null === $cache) {
         $cache = new MemoryCache();
     }
     $cachedAdapter = new CachedAdapter($adapter, $cache);
     if (array_key_exists($backendConfig['adapter'], static::$trackedOperations)) {
         $backendConfig['trackedOperations'] = static::$trackedOperations[$backendConfig['adapter']];
     }
     return new Backend($backendConfig, $this->app, $cachedAdapter, $filesystemConfig);
 }
Ejemplo n.º 18
0
 /**
  * Get content from a dir.
  *
  * @param string $directory
  * @param string $typ
  * @param bool   $recursive
  *
  * @return array
  */
 private function getContents(string $directory, string $typ, bool $recursive = false) : array
 {
     $contents = $this->driver->listContents($directory, $recursive);
     return $this->filterContentsByType($contents, $typ);
 }
Ejemplo n.º 19
0
 /**
  * Get the URL using a `getUrl()` method on the adapter.
  *
  * @param  string $path
  * @return string
  */
 protected function getFromMethod($path)
 {
     return $this->adapter->getUrl($path);
 }
Ejemplo n.º 20
0
 /**
  * {@inheritdoc}
  */
 public function rename($sourceKey, $targetKey)
 {
     return $this->adapter->rename($sourceKey, $targetKey);
 }