Determine if a string is a valid name for a DNS compatible Amazon S3
bucket.

DNS compatible bucket names can be used as a subdomain in a URL (e.g.,
"<bucket>.s3.amazonaws.com").

@param string $bucket Bucket name to check.

@return bool
971650
public static function isBucketDnsCompatible($bucket)
    {
        $bucketLen = strlen($bucket);

        return ($bucketLen >= 3 && $bucketLen <= 63) &&
            // Cannot look like an IP address
            !filter_var($bucket, FILTER_VALIDATE_IP) &&
            preg_match('/^[a-z0-9]([a-z0-9\-\.]*[a-z0-9])?$/', $bucket);
    }
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,
		);
	}
1153331
public static function isDomain($domain)
    {
        if (!is_string($domain)) {
            throw new \ErrorException('Accept string ' . gettype($domain) . ' given');
        }

        return  (bool) preg_match(
            '/^((https?|ftps?|ssl|url|git):\/\/)?[a-zA-Z0-9-_.]+\.[a-z]{2,6}$/',
            $domain
        );
    }
817259
private function quoteBucketName($bucketName, &$params)
    {
        if (!is_array($bucketName)) {
            return $this->db->quoteBucketName($bucketName);
        }

        foreach ($bucketName as $i => $bucket) {
            if ($bucket instanceof Query) {
                list($sql, $params) = $this->build($bucket, $params);

                $bucketName[$i] = "($sql) " . $this->db->quoteBucketName($i);
            }
            elseif (is_string($i)) {
                if (strpos($bucket, '(') === false) {
                    $bucket = $this->db->quoteBucketName($bucket);
                }

                $bucketName[$i] = "$bucket " . $this->db->quoteBucketName($i);
            }
            elseif (strpos($bucket, '(') === false) {
                if (preg_match('/^(.*?)(?i:\s+as|)\s+([^ ]+)$/', $bucket, $matches)) { // with alias
                    $bucketName[$i] = $this->db->quoteBucketName($matches[1]) . ' ' . $this->db->quoteBucketName($matches[2]);
                }
                else {
                    $bucketName[$i] = $this->db->quoteBucketName($bucket);
                }
            }
        }

        return reset($bucketName);
    }
903237
public static function isValidName($name, $strict = false)
    {
        $constants = self::getEnum();

        if ($strict) {
            return array_key_exists($name, $constants);
        }

        $keys = array_map('strtolower', array_keys($constants));

        return in_array(strtolower($name), $keys, true);
    }
692816
def _validate_name(name):
    
    if name is None:
        return

    # The first and las characters must be alphanumeric.
    if not all([name[0].isalnum(), name[-1].isalnum()]):
        raise ValueError("Bucket names must start and end with a number or letter.")
    return name
77275
protected function formatBucket(&$bucket)
    {
        $bucket->id          = (int) $bucket->id;
        $bucket->max_size    = (int) $bucket->max_size;
        $bucket->modified_by = (int) $bucket->modified_by ?: null;

        // --------------------------------------------------------------------------

        if (!empty($bucket->allowed_types)) {
            if (strpos($bucket->allowed_types, '|') !== false) {
                $aAllowedTypes = explode('|', $bucket->allowed_types);
            } else {
                $aAllowedTypes = explode(',', $bucket->allowed_types);
            }
        } else {
            $aAllowedTypes = $this->aDefaultAllowedTypes;
        }

        $aAllowedTypes = array_map(
            function ($sExt) {
                return preg_replace('/^\./', '', trim($sExt));
            },
            $aAllowedTypes
        );

        $aAllowedTypes = array_map([$this, 'sanitiseExtension'], $aAllowedTypes);
        $aAllowedTypes = array_unique($aAllowedTypes);
        $aAllowedTypes = array_values($aAllowedTypes);

        $bucket->allowed_types = $aAllowedTypes;

        if (isset($bucket->objectCount)) {
            $bucket->objectCount = (int) $bucket->objectCount;
        }
    }
193882
public static function validName(string $name): bool
    {
        $enumerables = self::getCache();
        $keys = array_keys($enumerables);

        return \in_array($name, $keys, true);
    }
496605
public static function isValidName( $name ): bool
	{
		$len = strlen($name);
		if( $len < 5 || ! preg_match('/^on[A-Z][a-zA-Z]*$/', $name) )
		{
			return false;
		}

		return $len < 256;
	}
1275517
def from_store_name(bucket_name, region=None):
    
    # Late-bind `region` for the sake of tests that inject the
    # AWS_REGION environment variable.
    if region is None:
        region = os.getenv('AWS_REGION')

    mostly_ok = _is_mostly_subdomain_compatible(bucket_name)

    if not mostly_ok:
        return CallingInfo(
            bucket_name=bucket_name,
            region=region,
            calling_format=connection.OrdinaryCallingFormat,
            ordinary_endpoint=must_resolve(region))
    else:
        if '.' in bucket_name:
            # The bucket_name might have been DNS compatible, but once
            # dots are involved TLS certificate validations will
            # certainly fail even if that's the case.
            return CallingInfo(
                bucket_name=bucket_name,
                calling_format=connection.OrdinaryCallingFormat,
                region=region,
                ordinary_endpoint=must_resolve(region))
        else:
            # If the bucket follows naming rules and has no dots in
            # the name, SubdomainCallingFormat can be used, with TLS,
            # world-wide.
            return CallingInfo(
                bucket_name=bucket_name,
                calling_format=connection.SubdomainCallingFormat,
                region=region,
                ordinary_endpoint=None)

    assert False
1189080
protected static String getBucketARN(String bucketName) throws IllegalArgumentException {
        return new StringBuilder().append(S3_ARN_PREFIX).append(bucketName).toString();
    }
1108568
public function deleteBucket(string $bucket)
    {
        try {
            $this->client->deleteBucket($bucket);
            return $this->success('删除Bucket成功');
        } catch (\Exception $exception) {
            return $this->error('调用阿里云接口出错：' . $exception->getMessage());
        }
    }
842208
public static function has($name) {
		if(empty($name)) {
			throw new InvalidArgumentException('Domain name can not be empty!');
		}
		if(!\App::$domain->has($name)) {
			return false;
		}
		$domain = \App::$domain->get($name);
		if(!$domain instanceof Domain) {
			return false;
		}
		return true;
	}
847750
public function isValidDomain()
    {
        $domain = isset($_SERVER[ 'HTTP_HOST' ])
            ? $_SERVER[ 'HTTP_HOST' ]
            : $_SERVER[ 'SERVER_NAME' ];

        if ($this->domain === $domain) {
            return true;
        }

        return false;
    }
129858
public function resolveBucket(string $address, string &$name = null): string
    {
        $bucket = null;
        $length = 0;
        foreach ($this->prefixes as $id => $prefix) {
            if (strpos($address, $prefix) === 0 && strlen($prefix) > $length) {
                $bucket = $id;
                $length = strlen($prefix);
            }
        }

        if (empty($bucket)) {
            throw new ResolveException("Unable to resolve bucket of `{$address}`.");
        }

        $name = substr($address, $length);

        return $bucket;
    }
636552
public function isBucketExist($bucketId)
    {
        $this->ensureAuthorized();
        $response = $this->client->b2ListBuckets($this->apiURL, $this->token);
        if ($response->isOk()) {
            $buckets = $response->get('buckets');
            if (!is_null($buckets)) {
                foreach ($buckets as $bucket) {
                    if ($bucketId == $bucket['bucketId']) {
                        return true;
                    }
                }
            }
        }

        return false;
    }
657684
public static function isNameSpaceAllowed(string $namespace): bool
    {
        $fixedNS = [
            'http://www.w3.org/2001/XMLSchema-instance',
            'http://www.w3.org/XML/1998/namespace',
        ];
        foreach ($fixedNS as $ns) {
            if (0 === strcasecmp($ns, $namespace)) {
                return true;
            }
        }
        $willcardNS = [
            'http://www.sat.gob.mx/',
        ];
        foreach ($willcardNS as $ns) {
            if (0 === strpos($namespace, $ns)) {
                return true;
            }
        }
        return false;
    }