WP_CLI

FileCache::validate_key()protectedWP-CLI 1.0

Validate cache key

Method of the class: FileCache{}

No Hooks.

Return

String. relative filename

Usage

// protected - for code of main (parent) or child class
$result = $this->validate_key( $key );
$key(string) (required)
cache key

FileCache::validate_key() code WP-CLI 2.8.0-alpha

protected function validate_key( $key ) {
	$url_parts = Utils\parse_url( $key, -1, false );
	if ( array_key_exists( 'path', $url_parts ) && ! empty( $url_parts['scheme'] ) ) { // is url
		$parts   = [ 'misc' ];
		$parts[] = $url_parts['scheme'] .
			( empty( $url_parts['host'] ) ? '' : '-' . $url_parts['host'] ) .
			( empty( $url_parts['port'] ) ? '' : '-' . $url_parts['port'] );
		$parts[] = substr( $url_parts['path'], 1 ) .
			( empty( $url_parts['query'] ) ? '' : '-' . $url_parts['query'] );
	} else {
		$key   = str_replace( '\\', '/', $key );
		$parts = explode( '/', ltrim( $key ) );
	}

	$parts = preg_replace( "#[^{$this->whitelist}]#i", '-', $parts );

	return implode( '/', $parts );
}