You are here

class S3Adapter in Flysystem - S3 2.0.x

Same name and namespace in other branches
  1. 8 src/Flysystem/Adapter/S3Adapter.php \Drupal\flysystem_s3\Flysystem\Adapter\S3Adapter

Overrides methods so it works with Drupal.

Hierarchy

  • class \Drupal\flysystem_s3\Flysystem\Adapter\S3Adapter extends \League\Flysystem\AwsS3v3\AwsS3Adapter

Expanded class hierarchy of S3Adapter

1 file declares its use of S3Adapter
S3.php in src/Flysystem/S3.php

File

src/Flysystem/Adapter/S3Adapter.php, line 14

Namespace

Drupal\flysystem_s3\Flysystem\Adapter
View source
class S3Adapter extends AwsS3Adapter {

  /**
   * {@inheritdoc}
   */
  public function has($path) {
    $location = $this
      ->applyPathPrefix($path);
    if ($this->s3Client
      ->doesObjectExist($this->bucket, $location, $this->options)) {
      return TRUE;
    }
    if ($this->s3Client
      ->doesObjectExist($this->bucket, $location . '/') === TRUE) {
      return TRUE;
    }
    else {
      return $this
        ->doesDirectoryExist($location);
    }
  }

  /**
   * {@inheritdoc}
   */
  public function getMetadata($path) {
    $metadata = parent::getMetadata($path);
    if ($metadata === FALSE) {
      return [
        'type' => 'dir',
        'path' => $path,
        'timestamp' => \Drupal::time()
          ->getRequestTime(),
        'visibility' => AdapterInterface::VISIBILITY_PUBLIC,
      ];
    }
    return $metadata;
  }

  /**
   * {@inheritdoc}
   */
  protected function upload($path, $body, Config $config) {
    $key = $this
      ->applyPathPrefix($path);
    $options = $this
      ->getOptionsFromConfig($config);
    $acl = isset($options['ACL']) ? $options['ACL'] : 'private';
    if (!isset($options['ContentType'])) {
      if (is_string($body)) {
        $options['ContentType'] = Util::guessMimeType($path, $body);
      }
      else {
        $options['ContentType'] = MimeType::detectByFilename($path);
      }
    }
    if (!isset($options['ContentLength'])) {
      $options['ContentLength'] = is_string($body) ? Util::contentSize($body) : Util::getStreamSize($body);
    }
    $this->s3Client
      ->upload($this->bucket, $key, $body, $acl, [
      'params' => $options,
    ]);
    return $this
      ->normalizeResponse($options, $key);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
S3Adapter::getMetadata public function
S3Adapter::has public function
S3Adapter::upload protected function