You are here

public function FetchManager::styleOriginalPath in Stage File Proxy 8

Helper to retrieves original path for a styled image.

Parameters

string $uri: A uri or path (may be prefixed with scheme).

bool $style_only: Indicates if, the function should only return paths retrieved from style paths. Defaults to TRUE.

Return value

bool|mixed|string A file URI pointing to the given original image. If $style_only is set to TRUE and $uri is no style-path, FALSE is returned.

Overrides FetchManagerInterface::styleOriginalPath

File

src/FetchManager.php, line 120

Class

FetchManager
Fetch manager.

Namespace

Drupal\stage_file_proxy

Code

public function styleOriginalPath($uri, $style_only = TRUE) {
  $scheme = StreamWrapperManager::getScheme($uri);
  if ($scheme) {
    $path = StreamWrapperManager::getTarget($uri);
  }
  else {
    $path = $uri;
    $scheme = $this->configFactory
      ->get('system.file')
      ->get('default_scheme');
  }

  // It is a styles path, so we extract the different parts.
  if (strpos($path, 'styles') === 0) {

    // Then the path is like styles/[style_name]/[schema]/[original_path].
    return preg_replace('/styles\\/.*\\/(.*)\\/(.*)/U', '$1://$2', $path);
  }
  elseif ($style_only == FALSE) {
    return "{$scheme}://{$path}";
  }
  else {
    return FALSE;
  }
}