function FileRepository::writeData

Same name in other branches
  1. 10 core/modules/file/src/FileRepository.php \Drupal\file\FileRepository::writeData()
  2. 11.x core/modules/file/src/FileRepository.php \Drupal\file\FileRepository::writeData()

Overrides FileRepositoryInterface::writeData

File

core/modules/file/src/FileRepository.php, line 89

Class

FileRepository
Provides a file entity repository.

Namespace

Drupal\file

Code

public function writeData(string $data, string $destination, int $replace = FileSystemInterface::EXISTS_RENAME) : FileInterface {
    if (!$this->streamWrapperManager
        ->isValidUri($destination)) {
        throw new InvalidStreamWrapperException("Invalid stream wrapper: {$destination}");
    }
    $uri = $this->fileSystem
        ->saveData($data, $destination, $replace);
    return $this->createOrUpdate($uri, $destination, $replace === FileSystemInterface::EXISTS_RENAME);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.