You are here

public function VendorStreamWrapperService::creatUrlFromUri in Vendor Stream Wrapper 8

Creates a public facing URL from URIs with the vendor:// schema.

Parameters

string $uri: The vendor:// prefixed URI to be convereted to a public facing URL.

Return value

string

  • If the $uri is prefixed with vendor://, and the path is valid, a public facing URL will be returned.
  • If the $uri is prefixed with vendor://, and the path is invalid, NULL is returned.
  • If $uri is not prefixed with vendor://, the passed $uri is returned unaltered.

Overrides VendorStreamWrapperServiceInterface::creatUrlFromUri

File

src/Service/VendorStreamWrapperService.php, line 29

Class

VendorStreamWrapperService
Provides services for the Vendor Stream Wrapper module.

Namespace

Drupal\vendor_stream_wrapper\Service

Code

public function creatUrlFromUri($uri) {
  if (strpos($uri, 'vendor://') === 0) {
    if ($wrapper = $this->streamWrapperService
      ->getViaUri($uri)) {
      return $wrapper
        ->getExternalUrl()
        ->toString();
    }
  }
  else {
    return $uri;
  }
}