You are here

public function Textimage::setTargetUri in Textimage 8.3

Same name and namespace in other branches
  1. 8.4 src/Textimage.php \Drupal\textimage\Textimage::setTargetUri()

Set image destination URI.

Parameters

string $uri: A valid URI.

Return value

$this

Overrides TextimageInterface::setTargetUri

File

src/Textimage.php, line 365

Class

Textimage
Provides a Textimage.

Namespace

Drupal\textimage

Code

public function setTargetUri($uri) {
  if ($this->uri) {
    throw new TextimageException("URI already set");
  }
  if ($uri) {
    if (!file_valid_uri($uri)) {
      throw new TextimageException("Invalid target URI '{$uri}' specified");
    }
    $dir_name = $this->fileSystem
      ->dirname($uri);
    $base_name = $this->fileSystem
      ->basename($uri);
    $valid_uri = $this
      ->createFilename($base_name, $dir_name);
    if ($uri != $valid_uri) {
      throw new TextimageException("Invalid target URI '{$uri}' specified");
    }
    $this
      ->setTargetExtension(pathinfo($uri, PATHINFO_EXTENSION));
    $this
      ->set('uri', $uri);
    $this
      ->set('caching', FALSE);
  }
  return $this;
}