function file_test_file_scan_callback

Same name in other branches
  1. 7.x modules/simpletest/tests/file.test \file_test_file_scan_callback()
  2. 8.9.x core/modules/file/tests/file_test/file_test.module \file_test_file_scan_callback()
  3. 10 core/modules/file/tests/file_test/file_test.module \file_test_file_scan_callback()
  4. 11.x core/modules/file/tests/file_test/file_test.module \file_test_file_scan_callback()

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 file_test_file_scan_callback()
file_test_file_scan_callback_reset in core/modules/file/tests/file_test/file_test.module
Reset static variables used by file_test_file_scan_callback().
ScanDirectoryTest::testOptionCallback in core/tests/Drupal/KernelTests/Core/File/ScanDirectoryTest.php
Check that the callback function is called correctly.
1 string reference to 'file_test_file_scan_callback'
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/file_test.module, line 333

Code

function file_test_file_scan_callback($filepath = NULL, $reset = FALSE) {
    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.