function FileTestHelper::fileScanCallback

Helper function for testing FileSystemInterface::scanDirectory().

Each time the function is called the file is stored in a static variable. When the function is called with no $filepath parameter, the results are returned.

Parameters

string|null $filepath: File path

bool $reset: (optional) If to reset the internal memory cache. If TRUE is passed, the first parameter has no effect. Defaults to FALSE.

Return value

array If $filepath is NULL, an array of all previous $filepath parameters

2 calls to FileTestHelper::fileScanCallback()
FileTestHelper::fileScanCallbackReset in core/modules/file/tests/file_test/src/FileTestHelper.php
Reset static variables used by FileTestHelper::fileScanCallback().
ScanDirectoryTest::testOptionCallback in core/tests/Drupal/KernelTests/Core/File/ScanDirectoryTest.php
Check that the callback function is called correctly.

File

core/modules/file/tests/file_test/src/FileTestHelper.php, line 128

Class

FileTestHelper
Helper for file tests.

Namespace

Drupal\file_test

Code

public static function fileScanCallback($filepath = NULL, $reset = FALSE) : array {
    static $files = [];
    if ($reset) {
        $files = [];
    }
    elseif ($filepath) {
        $files[] = $filepath;
    }
    return $files;
}

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