function FileStorage::ensureDirectory

Same name in other branches
  1. 8.9.x core/lib/Drupal/Component/PhpStorage/FileStorage.php \Drupal\Component\PhpStorage\FileStorage::ensureDirectory()
  2. 10 core/lib/Drupal/Component/PhpStorage/FileStorage.php \Drupal\Component\PhpStorage\FileStorage::ensureDirectory()
  3. 11.x core/lib/Drupal/Component/PhpStorage/FileStorage.php \Drupal\Component\PhpStorage\FileStorage::ensureDirectory()

Ensures the directory exists, has the right permissions, and a .htaccess.

For compatibility with open_basedir, the requested directory is created using a recursion logic that is based on the relative directory path/tree: It works from the end of the path recursively back towards the root directory, until an existing parent directory is found. From there, the subdirectories are created.

Parameters

string $directory: The directory path.

int $mode: The mode, permissions, the directory should have.

2 calls to FileStorage::ensureDirectory()
FileStorage::save in core/lib/Drupal/Component/PhpStorage/FileStorage.php
Saves PHP code to storage.
MTimeProtectedFastFileStorage::save in core/lib/Drupal/Component/PhpStorage/MTimeProtectedFastFileStorage.php
Saves PHP code to storage.

File

core/lib/Drupal/Component/PhpStorage/FileStorage.php, line 72

Class

FileStorage
Stores the code as regular PHP files.

Namespace

Drupal\Component\PhpStorage

Code

protected function ensureDirectory($directory, $mode = 0777) {
    if ($this->createDirectory($directory, $mode)) {
        FileSecurity::writeHtaccess($directory);
    }
}

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