You are here

public function LocalStream::mkdir in Drupal 9

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/StreamWrapper/LocalStream.php \Drupal\Core\StreamWrapper\LocalStream::mkdir()

Create a directory.

This method is called in response to mkdir()

Note, in order for the appropriate error message to be returned this method should not be defined if the wrapper does not support creating directories.

Note, the streamWrapper::$context property is updated if a valid context is passed to the caller function.

Parameters

string $path: Directory which should be created.

int $mode: The value passed to mkdir().

int $options: A bitwise mask of values, such as STREAM_MKDIR_RECURSIVE.

Return value

bool Returns TRUE on success or FALSE on failure.

Overrides PhpStreamWrapperInterface::mkdir

See also

mkdir()

PhpStreamWrapperInterface::rmdir()

http://php.net/manual/en/streamwrapper.mkdir.php

1 method overrides LocalStream::mkdir()
LocalReadOnlyStream::mkdir in core/lib/Drupal/Core/StreamWrapper/LocalReadOnlyStream.php
Support for mkdir().

File

core/lib/Drupal/Core/StreamWrapper/LocalStream.php, line 334

Class

LocalStream
Defines a Drupal stream wrapper base class for local files.

Namespace

Drupal\Core\StreamWrapper

Code

public function mkdir($uri, $mode, $options) {
  $this->uri = $uri;
  $recursive = (bool) ($options & STREAM_MKDIR_RECURSIVE);
  if ($recursive) {

    // $this->getLocalPath() fails if $uri has multiple levels of directories
    // that do not yet exist.
    $localpath = $this
      ->getDirectoryPath() . '/' . $this
      ->getTarget($uri);
  }
  else {
    $localpath = $this
      ->getLocalPath($uri);
  }

  /** @var \Drupal\Core\File\FileSystemInterface $file_system */
  $file_system = \Drupal::service('file_system');
  if ($options & STREAM_REPORT_ERRORS) {
    return $file_system
      ->mkdir($localpath, $mode, $recursive);
  }
  else {
    return @$file_system
      ->mkdir($localpath, $mode, $recursive);
  }
}