You are here

public function Dummy::getFiles in Libraries CDN API 7

Return all available file(s).

Parameters

array $version: Filter the returning array with this one.

Return value

array Return an array with available files of the library.

Overrides CDNBase::getFiles

File

modules/libraries_cdn_example_plugin/src/Plugin/LibrariesCDN/Dummy.php, line 83
Plugin: jsDelivr.

Class

Dummy
Class Dummy.

Namespace

Drupal\libraries_cdn_example_plugin\Plugin\LibrariesCDN

Code

public function getFiles(array $versions = array()) {
  $data = array();
  $keys = array_merge(range(0, 9), range('a', 'z'));
  $count_version = mt_rand(1, 5) + count($versions);
  $file_length = mt_rand(5, 10);
  for ($i = 0; $i < $count_version; $i++) {
    $files = array();
    $major = mt_rand(1, 10);
    $minor = mt_rand(1, 1000);
    for ($j = 0; $j < 10; $j++) {
      $key = '';
      for ($k = 0; $k < $file_length; $k++) {
        $key .= $keys[array_rand($keys)];
      }
      $ext = $j % 2 == 0 ? 'js' : 'css';
      $files[] = $key . '.' . $ext;
    }
    if (isset($versions[$i])) {
      $version = $versions[$i];
    }
    else {
      $version = $major . '.' . $minor;
    }
    $data[] = array(
      'files' => $files,
      'version' => $version,
    );
  }
  $results = array();
  foreach ($data as $asset) {
    if (isset($asset['version']) && isset($asset['files']) && is_array($asset['files'])) {
      $results[$asset['version']] = $this
        ->convertFiles($asset['files'], $asset['version']);
    }
  }
  return empty($versions) ? $results : array_intersect_key($results, array_combine(array_values($versions), array_values($versions)));
}