Same name in other branches
  1. 5.0.x src/Form/InfoForm.php \Drupal\advagg\Form\InfoForm::getRandomFile()
  2. 6.0.x src/Form/InfoForm.php \Drupal\advagg\Form\InfoForm::getRandomFile()
  3. 8.x-3.x src/Form/InfoForm.php \Drupal\advagg\Form\InfoForm::getRandomFile()

Get a (pseudo) random optimized file name.

Return value

bool|string The filename or FALSE if no valid files found.

1 call to InfoForm::getRandomFile()
InfoForm::buildForm in src/Form/InfoForm.php

File

src/Form/InfoForm.php, line 256

Class

InfoForm
View AdvAgg information for this site.

Namespace

Drupal\advagg\Form

Code

private function getRandomFile() {
    // Ensure the directory exists.
    $dir = 'public://js/optimized/';
    if (!is_dir($dir)) {
        return FALSE;
    }
    if ($handler = opendir($dir)) {
        while (($file = readdir($handler)) !== FALSE) {
            if (is_file($dir . $file) && pathinfo($file, PATHINFO_EXTENSION) == 'js') {
                closedir($handler);
                return $file;
            }
        }
        closedir($handler);
    }
    return FALSE;
}