/**
  * Write a file
  *
  * @param $path
  * @param $contents
  * @param null $config
  * @return array|bool
  */
 public function write($path, $contents, $config = null)
 {
     $type = 'file';
     $config = Util::ensureConfig($config);
     $result = compact('contents', 'type', 'size', 'path');
     if ($visibility = $config->get('visibility')) {
         $result['visibility'] = $visibility;
     }
     return $result;
 }
Exemple #2
0
 /**
  * {@inheritdoc}
  */
 public function storeContents($directory, array $contents, $recursive)
 {
     if ($recursive) {
         return $contents;
     }
     foreach ($contents as $index => $object) {
         $pathinfo = Util::pathinfo($object['path']);
         $object = array_merge($pathinfo, $object);
         if (!$recursive && $object['dirname'] !== $directory) {
             unset($contents[$index]);
             continue;
         }
         $contents[$index] = $object;
     }
     return $contents;
 }
 /**
  * Ensure parent directories of an object
  *
  * @param   string  $path  object path
  */
 public function ensureParentDirectories($path)
 {
     $object = $this->cache[$path];
     while ($object['dirname'] !== '' && !isset($this->cache[$object['dirname']])) {
         $object = Util::pathinfo($object['dirname']);
         $object['type'] = 'dir';
         $this->cache[$object['path']] = $object;
     }
 }
Exemple #4
0
 /**
  * Normalize a DataObject
  *
  * @param   DataObject  $object
  * @return  array       file metadata
  */
 protected function normalizeObject(DataObject $object)
 {
     $name = $object->getName();
     if ($this->prefix) {
         $name = substr($name, strlen($this->prefix));
     }
     $mimetype = explode('; ', $object->getContentType());
     return array('type' => 'file', 'dirname' => Util::dirname($name), 'path' => $name, 'timestamp' => strtotime($object->getLastModified()), 'mimetype' => reset($mimetype), 'size' => $object->getContentLength());
 }
Exemple #5
0
 protected function normalizeObject($object, $path = null)
 {
     $result = array('path' => $path ?: ltrim($object['path'], '/'));
     if (isset($object['modified'])) {
         $result['timestamp'] = strtotime($object['modified']);
     }
     $result = array_merge($result, Util::map($object, static::$resultMap));
     $result['type'] = $object['is_dir'] ? 'dir' : 'file';
     return $result;
 }
Exemple #6
0
 public function getMimetype($path)
 {
     if (!($data = $this->read($path))) {
         return false;
     }
     $data['mimetype'] = Util::guessMimeType($path, $data['contents']);
     return $data;
 }
Exemple #7
0
 /**
  * Update a file
  *
  * @param   string       $path
  * @param   string       $contents
  * @param   mixed        $config   Config object or visibility setting
  * @return  array|bool
  */
 public function update($path, $contents, $config = null)
 {
     $location = $this->prefix($path);
     $mimetype = Util::guessMimeType($path, $contents);
     if (($size = file_put_contents($location, $contents, LOCK_EX)) === false) {
         return false;
     }
     return compact('path', 'size', 'contents', 'mimetype');
 }
Exemple #8
0
 /**
  * Normalize a result from AWS
  *
  * @param   string  $object
  * @param   string  $path
  * @return  array   file metadata
  */
 protected function normalizeObject($object, $path = null)
 {
     $result = array('path' => $path ?: $object['Key']);
     if (isset($object['LastModified'])) {
         $result['timestamp'] = strtotime($object['LastModified']);
     }
     if (substr($result['path'], -1) === '/') {
         $result['type'] = 'dir';
         $result['path'] = rtrim($result['path'], '/');
         $result['dirname'] = Util::dirname($result['path']);
         return $result;
     }
     $result = array_merge($result, Util::map($object, static::$resultMap), array('type' => 'file'));
     $result['dirname'] = Util::dirname($result['path']);
     if (isset($result['contents'])) {
         $result['contents'] = (string) $result['contents'];
     }
     return $result;
 }
Exemple #9
0
 /**
  * Get a file/directory handler
  *
  * @param   string   $path
  * @param   Handler  $handler
  * @return  Handler  file or directory handler
  */
 public function get($path, Handler $handler = null)
 {
     $path = Util::normalizePath($path);
     if (!$handler) {
         $metadata = $this->getMetadata($path);
         $handler = $metadata['type'] === 'file' ? new File($this, $path) : new Directory($this, $path);
     }
     $handler->setPath($path);
     $handler->setFilesystem($this);
     return $handler;
 }
Exemple #10
0
 protected function normalizeObject($object, $path)
 {
     if (!isset($object['{DAV:}getcontentlength'])) {
         return array('type' => 'dir', 'path' => trim($path, '/'));
     }
     $result = Util::map($object, static::$resultMap);
     if (isset($object['{DAV:}getlastmodified'])) {
         $result['timestamp'] = strtotime($object['{DAV:}getlastmodified']);
     }
     $result['type'] = 'file';
     $result['path'] = trim($path, '/');
     return $result;
 }