function RecipeQuickStartTest::fileUnmanagedDeleteRecursive

Same name in other branches
  1. 10 core/tests/Drupal/Tests/Core/Recipe/RecipeQuickStartTest.php \Drupal\Tests\Core\Recipe\RecipeQuickStartTest::fileUnmanagedDeleteRecursive()

Deletes all files and directories in the specified path recursively.

Note this method has no dependencies on Drupal core to ensure that the test site can be torn down even if something in the test site is broken.

Parameters

string $path: A string containing either a URI or a file or directory path.

callable $callback: (optional) Callback function to run on each file prior to deleting it and on each directory prior to traversing it. For example, can be used to modify permissions.

Return value

bool TRUE for success or if path does not exist, FALSE in the event of an error.

See also

\Drupal\Core\File\FileSystemInterface::deleteRecursive()

1 call to RecipeQuickStartTest::fileUnmanagedDeleteRecursive()
RecipeQuickStartTest::tearDown in core/tests/Drupal/Tests/Core/Recipe/RecipeQuickStartTest.php

File

core/tests/Drupal/Tests/Core/Recipe/RecipeQuickStartTest.php, line 164

Class

RecipeQuickStartTest
Tests the quick-start command with recipes.

Namespace

Drupal\Tests\Core\Recipe

Code

protected function fileUnmanagedDeleteRecursive($path, $callback = NULL) : bool {
    if (isset($callback)) {
        call_user_func($callback, $path);
    }
    if (is_dir($path)) {
        $dir = dir($path);
        assert($dir instanceof \Directory);
        while (($entry = $dir->read()) !== FALSE) {
            if ($entry == '.' || $entry == '..') {
                continue;
            }
            $entry_path = $path . '/' . $entry;
            $this->fileUnmanagedDeleteRecursive($entry_path, $callback);
        }
        $dir->close();
        return rmdir($path);
    }
    return unlink($path);
}

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