You are here

private function InfoForm::getRandomFile in Advanced CSS/JS Aggregation 8.4

Same name and namespace in other branches
  1. 8.3 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
Form constructor.

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;
}