Esempio n. 1
0
 /**
  * @covers Drupal\amazons3\Matchable\BasicPath::__toString
  */
 public function testToString()
 {
     $path = new BasicPath('.*');
     $this->assertEquals($path->getPath(), (string) $path);
 }
 /**
  * Set the stream wrapper configuration using Drupal variables.
  *
  * @return StreamWrapperConfiguration
  *   A StreamWrapperConfiguration object.
  */
 public static function fromDrupalVariables()
 {
     $config = self::fromConfig(array('bucket' => static::variable_get('amazons3_bucket', NULL)));
     $defaults = $config->defaults();
     $config->setHostname(static::variable_get('amazons3_hostname', $defaults['hostname']));
     // CNAME support for customizing S3 URLs.
     if (static::variable_get('amazons3_cname', FALSE)) {
         $domain = static::variable_get('amazons3_domain', $defaults['domain']);
         if (strlen($domain) > 0) {
             $config->setDomain($domain);
         } else {
             $config->setDomain($config->getBucket());
         }
         if (static::variable_get('amazons3_cloudfront', $defaults['cloudFront'])) {
             $path = static::variable_get('amazons3_cloudfront_private_key', $defaults['cloudFrontPrivateKey']);
             $keyPairId = static::variable_get('amazons3_cloudfront_keypair_id', $defaults['cloudFrontKeyPairId']);
             $config->setCloudFrontCredentials($path, $keyPairId);
             $config->serveWithCloudFront();
         }
     } else {
         $config->setDomain(static::getS3Domain($config->getBucket()));
     }
     // Check whether local file caching is turned on.
     if (static::variable_get('amazons3_cache', $defaults['caching'])) {
         $config->enableCaching();
         $config->setCacheLifetime(static::variable_get('amazons3_cache_expiration', NULL));
     } else {
         $config->disableCaching();
     }
     // Torrent list.
     $torrentPaths = static::variable_get('amazons3_torrents', array());
     $paths = BasicPath::factory($torrentPaths);
     if (!empty($paths)) {
         $config->setTorrentPaths(new MatchablePaths($paths));
     }
     // Presigned url-list.
     $presigned_urls = static::variable_get('amazons3_presigned_urls', array());
     $paths = array();
     foreach ($presigned_urls as $presigned_url) {
         $paths[] = new PresignedPath($presigned_url['pattern'], $presigned_url['timeout']);
     }
     if (!empty($paths)) {
         $config->setPresignedPaths(new MatchablePaths($paths));
     }
     // Force "save as" list.
     $saveAsPaths = static::variable_get('amazons3_saveas', array());
     $paths = BasicPath::factory($saveAsPaths);
     if (!empty($paths)) {
         $config->setSaveAsPaths(new MatchablePaths($paths));
     }
     // Reduced Redundancy Storage.
     $rrsPaths = static::variable_get('amazons3_rrs', array());
     $paths = BasicPath::factory($rrsPaths);
     if (!empty($paths)) {
         $config->setReducedRedundancyPaths(new MatchablePaths($paths));
     }
     return $config;
 }
 /**
  * @covers \Drupal\amazons3\StreamWrapper::getOptions
  * @covers \Drupal\amazons3\StreamWrapper::useRrs
  */
 public function testReducedRedundancyStorage()
 {
     $config = StreamWrapperConfiguration::fromConfig(['bucket' => 'bucket.example.com', 'caching' => FALSE, 'reducedRedundancyPaths' => new MatchablePaths(BasicPath::factory(array('*')))]);
     $wrapper = new StreamWrapper($config);
     $wrapper->setUri('s3://bucket.example.com/styles/thumbnail/image.jpg');
     $options = $wrapper->getOptions();
     $this->assertArrayHasKey('StorageClass', $options);
     $this->assertEquals('REDUCED_REDUNDANCY', $options['StorageClass']);
 }
 /**
  * @covers Drupal\amazons3\Matchable\MatchablePaths::match
  */
 public function testNoMatch()
 {
     $paths = BasicPath::factory(array('foo', 'bar'));
     $mp = new MatchablePaths($paths);
     $this->assertFalse($mp->match('no-match'));
 }