private function ImageStyleDownloadController::sourceImageExists in Drupal 10
Checks whether the provided source image exists.
Parameters
string $image_uri: The URI for the source image.
bool $token_is_valid: Whether a valid image token was supplied.
Return value
bool Whether the source image exists.
File
- core/
modules/ image/ src/ Controller/ ImageStyleDownloadController.php, line 232  
Class
- ImageStyleDownloadController
 - Defines a controller to serve image styles.
 
Namespace
Drupal\image\ControllerCode
private function sourceImageExists(string $image_uri, bool $token_is_valid) : bool {
  $exists = file_exists($image_uri);
  // If the file doesn't exist, we can stop here.
  if (!$exists) {
    return FALSE;
  }
  if ($token_is_valid) {
    return TRUE;
  }
  if (StreamWrapperManager::getScheme($image_uri) !== 'public') {
    return TRUE;
  }
  $image_path = $this->fileSystem
    ->realpath($image_uri);
  $private_path = Settings::get('file_private_path');
  if ($private_path) {
    $private_path = realpath($private_path);
    if ($private_path && strpos($image_path, $private_path) === 0) {
      return FALSE;
    }
  }
  return TRUE;
}