Get valid GridFS collection associated with bucket.

@param BucketInterface $bucket Bucket instance.

@return Bucket
962326
protected function gridFS(BucketInterface $bucket): Bucket
    {
        if (empty($this->database)) {
            $this->database = new Database(
                new Manager($this->options['connection']),
                $this->options['database']
            );
        }

        return $this->database->selectGridFSBucket([
            'bucketName' => $bucket->getOption('bucket')
        ]);
    }
1335306
public function getBucketCors($bucket, $options = NULL)
    {
        $this->precheckCommon($bucket, NULL, $options, false);
        $options[self::OSS_BUCKET] = $bucket;
        $options[self::OSS_METHOD] = self::OSS_HTTP_GET;
        $options[self::OSS_OBJECT] = '/';
        $options[self::OSS_SUB_RESOURCE] = 'cors';
        $response = $this->auth($options);
        $result = new GetCorsResult($response, __FUNCTION__);
        return $result->getData();
    }
158498
public function getDocumentBucket(string $className) : Bucket
    {
        $className = $this->classNameResolver->getRealClass($className);

        /** @var ClassMetadata $metadata */
        $metadata = $this->metadataFactory->getMetadataFor($className);
        if (! $metadata->isFile) {
            throw MongoDBException::documentBucketOnlyAvailableForGridFSFiles($className);
        }

        $bucketName = $metadata->getBucketName();

        if (! $bucketName) {
            throw MongoDBException::documentNotMappedToCollection($className);
        }

        if (! isset($this->documentBuckets[$className])) {
            $db = $this->getDocumentDatabase($className);

            $options = ['bucketName' => $bucketName];
            if ($metadata->readPreference !== null) {
                $options['readPreference'] = new ReadPreference($metadata->readPreference, $metadata->readPreferenceTags);
            }

            $this->documentBuckets[$className] = $db->selectGridFSBucket($options);
        }

        return $this->documentBuckets[$className];
    }
277666
protected function doGetGridFS($prefix)
    {
        $riakGridFS = $this->riak->getGridFS($prefix);

        return new GridFS($this, $riakGridFS, $this->eventManager);
    }
479255
private List<GridFSDBFile> getGFSDBFiles(BasicDBObject mongoQuery, BasicDBObject sort, String collectionName,
            int maxResult, int firstResult)
    {
        KunderaGridFS gfs = new KunderaGridFS(mongoDb, collectionName);
        return gfs.find(mongoQuery, sort, firstResult, maxResult);
    }
405867
public function getObject($bucket, $key, array $params = [])
    {
        $params['Bucket'] = $bucket;
        $params['Key'] = $key;

        return $this->instance->getObject($params);
    }
233982
public static function get(ContainerInterface $container) {
    $test_mode = $container
      ->get('config.factory')
      ->get('acm.connector')
      ->get('test_mode');

    if ($test_mode) {
      return $container->get('acm.test_agent_api');
    }

    return $container->get('acm.agent_api');
  }
114140
public function selectGridFSBucket(array $options = [])
    {
        $options += [
            'readConcern' => $this->readConcern,
            'readPreference' => $this->readPreference,
            'typeMap' => $this->typeMap,
            'writeConcern' => $this->writeConcern,
        ];

        return new Bucket($this->manager, $this->databaseName, $options);
    }
1080673
private function getPersisterFor($scn)
    {
        $reflobj = new \ReflectionObject($this->storageEngine);
        $accessor = $reflobj->getMethod('getPersisterFor');
        $accessor->setAccessible(true);
        return $accessor->invoke($this->storageEngine, $scn);
    }
347275
public function buildBucket(BucketInterface $bucket)
    {
        if ($bucket->getType() !== BucketInterface::TYPE_SIGNIFICANT_TERM) {
            throw new \InvalidArgumentException("Query builder : invalid aggregation type {$bucket->getType()}.");
        }
        $aggrepationParams = [
            'field'                 => $bucket->getField(),
            'size'                  => $bucket->getSize(),
            'min_doc_count'         => $bucket->getMinDocCount(),
            $bucket->getAlgorithm() => new \stdClass(),
        ];

        return ['significant_terms' => $aggrepationParams];
    }
105434
public function openBucket(string $name): Bucket
    {
        $couchbase = $this->getCouchbase();
        if ($this->bucketPassword === '') {
            return $couchbase->openBucket($name);
        }

        return $couchbase->openBucket($name, $this->bucketPassword);
    }
231357
public static function getBucketLogging($bucket)
	{
		$rest = new S3Request('GET', $bucket, '', self::$endpoint);
		$rest->setParameter('logging', null);
		$rest = $rest->getResponse();
		if ($rest->error === false && $rest->code !== 200)
			$rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status');
		if ($rest->error !== false)
		{
			self::__triggerError(sprintf("S3::getBucketLogging({$bucket}): [%s] %s",
			$rest->error['code'], $rest->error['message']), __FILE__, __LINE__);
			return false;
		}
		if (!isset($rest->body->LoggingEnabled)) return false; // No logging
		return array(
			'targetBucket' => (string)$rest->body->LoggingEnabled->TargetBucket,
			'targetPrefix' => (string)$rest->body->LoggingEnabled->TargetPrefix,
		);
	}
118499
public function getGridFS($name = 'fs')
    {
        // return from pool
        if ($this->collectionPoolEnabled && isset($this->collectionPool[$name])) {
            return $this->collectionPool[$name];
        }

        // no object in pool - init new
        $classDefinition = $this->getCollectionDefinition($name, array('gridfs' => true));
        $className = $classDefinition->getClass();

        // create collection class
        $collection = new $className($this, $name, $classDefinition);
        if (!$collection instanceof \Sokil\Mongo\GridFS) {
            throw new Exception('Must be instance of \Sokil\Mongo\GridFS');
        }

        // store to pool
        if ($this->collectionPoolEnabled) {
            $this->collectionPool[$name] = $collection;
        }

        // return
        return $collection;
    }
137506
public function determineBucketRegionAsync($bucketName)
    {
        $command = $this->getCommand('HeadBucket', ['Bucket' => $bucketName]);
        $handlerList = clone $this->getHandlerList();
        $handlerList->remove('s3.permanent_redirect');
        $handlerList->remove('signer');
        $handler = $handlerList->resolve();

        return $handler($command)
            ->then(static function (ResultInterface $result) {
                return $result['@metadata']['headers']['x-amz-bucket-region'];
            }, function (AwsException $e) {
                $response = $e->getResponse();
                if ($response === null) {
                    throw $e;
                }

                if ($e->getAwsErrorCode() === 'AuthorizationHeaderMalformed') {
                    $region = $this->determineBucketRegionFromExceptionBody(
                        $response
                    );
                    if (!empty($region)) {
                        return $region;
                    }
                    throw $e;
                }

                return $response->getHeaderLine('x-amz-bucket-region');
            });
    }
996268
public function getObjectsByCollection(CollectionInterface $collection)
    {
        $objects = array();
        $that = $this;
        $bucketName = $this->bucketName;
        $keyPrefix = $this->keyPrefix;
        $bucket = $this->getCurrentBucket();

        foreach ($this->resourceRepository->findByCollectionName($collection->getName()) as $resource) {
            /** @var \Neos\Flow\ResourceManagement\PersistentResource $resource */
            $object = new StorageObject();
            $object->setFilename($resource->getFilename());
            $object->setSha1($resource->getSha1());
            $object->setStream(function () use ($that, $bucketName, $keyPrefix, $bucket, $resource) {
                $stream = $bucket->object($keyPrefix . $resource->getSha1())->downloadAsStream();
                return StreamWrapper::getResource($stream);
            });
            $objects[] = $object;
        }

        return $objects;
    }
757243
private static function getTokenStorage(ContainerInterface $container): CsrfTokenStorageInterface
    {
        assert($container->has(CsrfTokenStorageInterface::class) === true);
        /** @var CsrfTokenStorageInterface $csrfStorage */
        $csrfStorage = $container->get(CsrfTokenStorageInterface::class);

        return $csrfStorage;
    }
979023
public function dropBucket($bucket){
        $err = $this->subBucketManager->dropBucket($bucket);
        if($err){
            return $this->error($err->message(), ['errorCode'=>$err->code()]);
        }
        return $this->success('操作成功');
    }