/** * {@inheritdoc} */ function setUri($uri) { // file_stream_wrapper_get_instance_by_scheme() assumes that all schemes // can work without a directory, but S3 requires a bucket. If a raw scheme // is passed in, we append our default bucket. if ($uri == 's3://') { $uri = 's3://' . $this->config->getBucket(); } $this->uri = S3Url::factory($uri); }
/** * Overrides factory() to support bucket configs. * * @param string $url * Full URL used to create a Url object. * @param \Drupal\amazons3\StreamWrapperConfiguration $config * (optional) Configuration to associate with this URL. * * @throws \InvalidArgumentException * Thrown when $url cannot be parsed by parse_url(). * * @return static * An S3Url. */ public static function factory($url, StreamWrapperConfiguration $config = null) { !$config ? $bucket = null : ($bucket = $config->getBucket()); $defaults = array('scheme' => 's3', 'host' => $bucket, 'path' => null, 'port' => null, 'query' => null, 'user' => null, 'pass' => null, 'fragment' => null); if (false === ($parts = parse_url($url))) { throw new \InvalidArgumentException('Was unable to parse malformed url: ' . $url); } $parts += $defaults; return new static($parts['host'], substr($parts['path'], 1)); }