public function CdnBase::getLocalCopy in Libraries CDN API 8
Copy a library from the CDN to the local filesystem.
Parameters
array $versions: The library versions to copy.
Overrides CdnBaseInterface::getLocalCopy
File
- src/
CdnBase.php, line 254 - Class CdnBase.
Class
- CdnBase
- Class CdnBase.
Namespace
Drupal\libraries_cdnCode
public function getLocalCopy(array $versions = array()) {
$assets = $this
->getFiles();
if (!empty($versions)) {
$assets = array_intersect_key($assets, array_combine($versions, $versions));
}
foreach ($assets as $version => $files) {
foreach ($files as $file) {
if (!$this
->isLocalAvailable($file, $version)) {
$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);
}
}
}
}
}