Aws\S3\S3Client::getLocationConstraintMiddleware PHP Method

getLocationConstraintMiddleware() private method

Provides a middleware that removes the need to specify LocationConstraint on CreateBucket.
    private function getLocationConstraintMiddleware()
    {
        $region = $this->getRegion();
        return static function (callable $handler) use($region) {
            return function (Command $command, $request = null) use($handler, $region) {
                if ($command->getName() === 'CreateBucket') {
                    $locationConstraint = isset($command['CreateBucketConfiguration']['LocationConstraint']) ? $command['CreateBucketConfiguration']['LocationConstraint'] : null;
                    if ($locationConstraint === 'us-east-1') {
                        unset($command['CreateBucketConfiguration']);
                    } elseif ('us-east-1' !== $region && empty($locationConstraint)) {
                        $command['CreateBucketConfiguration'] = ['LocationConstraint' => $region];
                    }
                }
                return $handler($command, $request);
            };
        };
    }