Exemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function write($key, $content)
 {
     $this->initialize();
     $path = $this->computePath($key);
     $this->ensureDirectoryExists(\Gaufrette\Util\Path::dirname($path), true);
     if ($this->sftp->put($path, $content)) {
         return $this->sftp->size($path);
     }
     return false;
 }
Exemplo n.º 2
0
 /**
  * {@inheritdoc}
  */
 public function keys()
 {
     $this->initialize();
     $results = $this->sftp->listDirectory($this->directory, true);
     $files = array_map(array($this, 'computeKey'), $results['files']);
     $dirs = array();
     foreach ($files as $file) {
         if ('.' !== ($dirname = \Gaufrette\Util\Path::dirname($file))) {
             $dirs[] = $dirname;
         }
     }
     $keys = array_merge($files, $dirs);
     sort($keys);
     return $keys;
 }
Exemplo n.º 3
0
 /**
  * {@inheritdoc}
  */
 public function open(StreamMode $mode)
 {
     $baseDirPath = \Gaufrette\Util\Path::dirname($this->path);
     if ($mode->allowsWrite() && !is_dir($baseDirPath)) {
         @mkdir($baseDirPath, 0755, true);
     }
     try {
         $fileHandle = @fopen($this->path, $mode->getMode());
     } catch (\Exception $e) {
         $fileHandle = false;
     }
     if (false === $fileHandle) {
         throw new \RuntimeException(sprintf('File "%s" cannot be opened', $this->path));
     }
     $this->mode = $mode;
     $this->fileHandle = $fileHandle;
     return true;
 }
Exemplo n.º 4
0
 /**
  * Creates the specified directory and its parent directories.
  *
  * @param string $directory Directory to create
  *
  * @throws RuntimeException if the directory could not be created
  */
 protected function createDirectory($directory)
 {
     // create parent directory if needed
     $parent = \Gaufrette\Util\Path::dirname($directory);
     if (!$this->isDir($parent)) {
         $this->createDirectory($parent);
     }
     // create the specified directory
     $created = ftp_mkdir($this->getConnection(), $directory);
     if (false === $created) {
         throw new \RuntimeException(sprintf('Could not create the \'%s\' directory.', $directory));
     }
 }
Exemplo n.º 5
0
 /**
  * {@inheritdoc}
  */
 public function rename($sourceKey, $targetKey)
 {
     $targetPath = $this->computePath($targetKey);
     $this->ensureDirectoryExists(\Gaufrette\Util\Path::dirname($targetPath), true);
     return rename($this->computePath($sourceKey), $targetPath);
 }
Exemplo n.º 6
0
 /**
  * {@inheritdoc}
  */
 public function keys()
 {
     $this->ensureBucketExists();
     $list = $this->service->get_object_list($this->bucket);
     $keys = array();
     foreach ($list as $file) {
         if ('.' !== \Gaufrette\Util\Path::dirname($file)) {
             $keys[] = \Gaufrette\Util\Path::dirname($file);
         }
         $keys[] = $file;
     }
     sort($keys);
     return $keys;
 }
Exemplo n.º 7
0
 /**
  * {@inheritdoc}
  */
 public function keys()
 {
     $metadata = $this->client->getMetaData('/', true);
     if (!isset($metadata['contents'])) {
         return array();
     }
     $keys = array();
     foreach ($metadata['contents'] as $value) {
         $file = ltrim($value['path'], '/');
         $keys[] = $file;
         if ('.' !== ($dirname = \Gaufrette\Util\Path::dirname($file))) {
             $keys[] = $dirname;
         }
     }
     sort($keys);
     return $keys;
 }