You are here

public function CDNBase::getLocalCopy in Libraries CDN API 7

Copy a library from the CDN to the local filesystem.

Parameters

array $versions: The library versions to copy.

Overrides CDNBaseInterface::getLocalCopy

File

src/Type/CDNBase.php, line 250
Class CDNBase.

Class

CDNBase
Class CDNBase.

Namespace

Drupal\libraries_cdn\Type

Code

public function getLocalCopy(array $versions = array(), array $indexes = array()) {
  $assets = $this
    ->getFiles($versions);
  if (!empty($versions)) {
    $assets = array_intersect_key($assets, array_combine($versions, $versions));
  }
  foreach ($assets as $version => $files) {
    if (empty($indexes)) {
      $indexes = array_keys(array_values($files));
    }
    foreach ($files as $index => $file) {
      if (!$this
        ->isLocalAvailable($file, $version)) {
        if (in_array($index, $indexes)) {
          $directory = $this
            ->getLocalDirectoryName($version);
          $this->drupal7
            ->file_prepare_directory($directory, FILE_CREATE_DIRECTORY);
          $this->drupal7
            ->file_prepare_directory($directory, FILE_MODIFY_PERMISSIONS);
          $request = $this
            ->request($this
            ->getScheme() . ':' . $file);
          if ($request['code'] == 200) {
            $this->drupal7
              ->file_unmanaged_save_data($request['data'], $this
              ->getLocalFileName($file, $version), FILE_EXISTS_REPLACE);
          }
        }
      }
    }
  }
}