Esempio n. 1
1
 /**
  * Remove file or a directory
  *
  * @param $path
  * @return void
  */
 public function remove($path)
 {
     if (!$this->filesystem->has($path)) {
         return;
     }
     $meta = $this->filesystem->getMetadata($path);
     if ($meta['type'] === 'file') {
         $this->filesystem->delete($path);
     } else {
         $this->filesystem->deleteDir($path);
     }
 }
 public function testGetMetadata()
 {
     $data = $this->filesystem->getMetadata('2.txt');
     $this->assertArrayHasKey('type', $data);
     $this->assertArrayHasKey('dirname', $data);
     $this->assertArrayHasKey('path', $data);
     $this->assertArrayHasKey('timestamp', $data);
     $this->assertArrayHasKey('mimetype', $data);
     $this->assertArrayHasKey('size', $data);
 }
Esempio n. 3
0
	/**
	 * {@inheritdoc}
	 */
	public function filetype($path) {
		if ($path === '' or $path === '/' or $path === '.') {
			return 'dir';
		}
		try {
			$info = $this->flysystem->getMetadata($this->buildPath($path));
		} catch (FileNotFoundException $e) {
			return false;
		}
		return $info['type'];
	}
Esempio n. 4
0
 /**
  * @inheritdoc
  */
 public function getMetadata($path)
 {
     try {
         $return = $this->fileSystem->getMetadata($this->getInnerPath($path));
     } catch (FileNotFoundException $e) {
         throw $this->exceptionWrapper($e, $path);
     }
     if ($return !== false) {
         $return = array_merge($return, pathinfo($path), ["path" => $path]);
     }
     return $return;
 }
Esempio n. 5
0
 /**
  * Get an object from the filesystem based on its path.
  *
  * Dependening on the adapter in the underlying flysystem, this might treat
  * empty directories as if they would not exist (e.g. for ZipArchiveAdapter).
  *
  * @param   string  $path
  * @return  FSObject|null
  */
 public function get($path)
 {
     // TODO: This does not deal with ~ for home directory.
     assert(is_string($path));
     // For ZipArchiveAdapter this is required to get the directories correctly,
     // as Filesystem::get will raise.
     if ($this->filesystem->listContents($path)) {
         return new Directory($this, $path);
     }
     try {
         $info = $this->filesystem->getMetadata($path);
         if ($info) {
             if ($info["type"] == "file") {
                 return new File($this, $path);
             }
             return new Directory($this, $path);
         }
     } catch (\League\Flysystem\FileNotFoundException $e) {
         return null;
     }
     return null;
 }
Esempio n. 6
0
 /**
  * @inheritdoc
  */
 protected function _stat($path)
 {
     $stat = array('size' => 0, 'ts' => time(), 'read' => true, 'write' => true, 'locked' => false, 'hidden' => false, 'mime' => 'directory');
     // If root, just return from above
     if ($this->root == $path) {
         $stat['name'] = $this->root;
         return $stat;
     }
     // If not exists, return empty
     //        if ( !$this->fs->has($path)) {
     //            return array();
     //        }
     //
     //        $meta = $this->fs->getMetadata($path);
     try {
         $meta = $this->fs->getMetadata($path);
     } catch (FileNotFoundException $e) {
         $path = $path . '/';
         try {
             $meta = $this->fs->getMetadata($path);
         } catch (FileNotFoundException $e) {
             return array();
         }
     }
     // Get timestamp/size
     $stat['ts'] = isset($meta['timestamp']) ? $meta['timestamp'] : $this->fs->getTimestamp($path);
     $stat['size'] = isset($meta['size']) ? $meta['size'] : $this->fs->getSize($path);
     // Check if file, if so, check mimetype
     if ($meta['type'] == 'file') {
         $stat['mime'] = isset($meta['mimetype']) ? $meta['mimetype'] : $this->fs->getMimetype($path);
         $imgMimes = ['image/jpeg', 'image/png', 'image/gif'];
         if ($this->urlBuilder && in_array($stat['mime'], $imgMimes)) {
             $stat['url'] = $this->urlBuilder->getUrl($path, ['ts' => $stat['ts']]);
             $stat['tmb'] = $this->urlBuilder->getUrl($path, ['ts' => $stat['ts'], 'w' => $this->tmbSize, 'h' => $this->tmbSize, 'fit' => $this->options['tmbCrop'] ? 'crop' : 'contain']);
         }
     }
     //        if (!isset($stat['url']) && $this->fs->getUrl()) {
     //            $stat['url'] = 1;
     //        }
     return $stat;
 }
 /**
  * @param Payload $payload
  * @param Messenger $messenger
  * @return PromiseInterface
  */
 public function stat(Payload $payload, Messenger $messenger)
 {
     $stat = $this->flysystem->getMetadata($payload['path']);
     return \React\Promise\resolve(['size' => $stat['size'], 'atime' => $stat['timestamp'], 'mtime' => $stat['timestamp'], 'ctime' => $stat['timestamp']]);
 }
Esempio n. 8
0
 /**
  * Get a file's metadata
  *
  * ```php
  * getMetadata('cache/file.tmp')
  * getMetadata('~/file.tmp$/')
  * ```
  *
  * @param  string $path path to file or regexp pattern
  * @return array|false           file metadata or FALSE when fails
  *                               to fetch it from existing file
  */
 public function getMetadata($path)
 {
     if (StringHelper::isRegexp($path) && !($path = $this->searchByPattern($path))) {
         return false;
     }
     try {
         if ($metadata = parent::getMetadata($path)) {
             if (!isset($metadata['dirname'])) {
                 $metadata['dirname'] = FileHelper::dirname($metadata['path']);
             }
             if (!isset($metadata['basename'])) {
                 $metadata['basename'] = FileHelper::basename($metadata['path']);
             }
         }
         return $metadata;
     } catch (\Exception $e) {
         $this->errors[] = $e->getMessage();
     }
     return false;
 }