class CDNJS in Libraries CDN API 7
Same name and namespace in other branches
- 8 src/Plugin/LibrariesCdn/CdnJs.php \Drupal\libraries_cdn\Plugin\LibrariesCdn\CdnJs
Class CDNJS.
Plugin annotation
@LibrariesCDNPlugin(
id = "cdnjs",
description = "CDNJS Integration",
arguments = {
"@drupal7"
}
)
Hierarchy
- class \Drupal\libraries_cdn\Type\CDNBase extends \Drupal\Component\Plugin\PluginBase implements CDNBaseInterface
- class \Drupal\libraries_cdn\Plugin\LibrariesCDN\CDNJS
Expanded class hierarchy of CDNJS
1 file declares its use of CDNJS
- CDNJSTest.php in tests/
src/ Plugin/ LibrariesCDN/ CDNJSTest.php - Contains \Drupal\Tests\Libraries_cdn\Plugin\LibrariesCDN\CDNJSTest.
File
- src/
Plugin/ LibrariesCDN/ CDNJS.php, line 25 - Plugin: CDNJS.
Namespace
Drupal\libraries_cdn\Plugin\LibrariesCDNView source
class CDNJS extends CDNBase {
/**
* {@inheritdoc}
*/
public function __construct(array $configuration, $plugin_id, array $plugin_definition, Drupal7 $drupal7) {
if (empty($configuration['urls'])) {
$configuration['urls'] = array();
}
$configuration['urls'] += array(
'isAvailable' => 'http://api.cdnjs.com/libraries?search=%s',
'getInformation' => 'http://api.cdnjs.com/libraries/%s',
'getVersions' => 'http://api.cdnjs.com/libraries/%s',
'getFiles' => 'http://api.cdnjs.com/libraries/%s',
'search' => 'http://api.cdnjs.com/libraries?search=%s&fields=version,assets,description',
'convertFiles' => '//cdnjs.cloudflare.com/ajax/libs/%s/%s/',
);
parent::__construct($configuration, $plugin_id, $plugin_definition, $drupal7);
}
/**
* {@inheritdoc}
*/
public function formatData($function, array $data = array()) {
switch ($function) {
case 'search':
case 'isAvailable':
return isset($data['results']) ? (array) $data['results'] : $data;
case 'getVersions':
case 'getFiles':
return isset($data['assets']) ? (array) $data['assets'] : $data;
case 'getLatestVersion':
return isset($data['version']) ? $data['version'] : NULL;
default:
return $data;
}
}
/**
* {@inheritdoc}
*/
public function getVersions() {
if (!$this
->isAvailable()) {
return array();
}
$data = $this
->formatData(__FUNCTION__, $this
->query($this
->getURL(__FUNCTION__)));
return array_filter(array_map(function ($v) {
return isset($v['version']) ? $v['version'] : NULL;
}, $data));
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CDNBase:: |
public | function | ||
CDNBase:: |
public | function |
Return the configuration of the object. Overrides CDNBaseInterface:: |
|
CDNBase:: |
public | function |
Return all available file(s). Overrides CDNBaseInterface:: |
1 |
CDNBase:: |
public | function |
Get library information. Overrides CDNBaseInterface:: |
1 |
CDNBase:: |
public | function |
Get latest version available of a library. Overrides CDNBaseInterface:: |
|
CDNBase:: |
public | function |
Get the library in use. Overrides CDNBaseInterface:: |
|
CDNBase:: |
public | function |
Copy a library from the CDN to the local filesystem. Overrides CDNBaseInterface:: |
|
CDNBase:: |
public | function |
Get the local directory name of a library. Overrides CDNBaseInterface:: |
|
CDNBase:: |
public | function |
Get the local file name of a library file. Overrides CDNBaseInterface:: |
|
CDNBase:: |
public | function |
Get the default scheme. Overrides CDNBaseInterface:: |
|
CDNBase:: |
public | function |
Get a particular URL. Overrides CDNBaseInterface:: |
|
CDNBase:: |
public | function |
Get URLs. Overrides CDNBaseInterface:: |
|
CDNBase:: |
public | function |
Check if library is available. Overrides CDNBaseInterface:: |
1 |
CDNBase:: |
public | function |
Check if a file is available locally. Overrides CDNBaseInterface:: |
|
CDNBase:: |
public | function |
Request wrapper for querying a CDN. Overrides CDNBaseInterface:: |
|
CDNBase:: |
public | function |
Make an HTTP Request. Overrides CDNBaseInterface:: |
|
CDNBase:: |
public | function |
Perform a search for a library. Overrides CDNBaseInterface:: |
1 |
CDNBase:: |
public | function |
Set the configuration of the object. Overrides CDNBaseInterface:: |
|
CDNBase:: |
public | function |
Set the library to work with. Overrides CDNBaseInterface:: |
|
CDNBase:: |
public | function |
Set default scheme for an url. Overrides CDNBaseInterface:: |
|
CDNBase:: |
public | function |
Set a particular URL. Overrides CDNBaseInterface:: |
|
CDNBase:: |
public | function |
Set URLs. Overrides CDNBaseInterface:: |
|
CDNJS:: |
public | function |
Return the data to use in each method. Overrides CDNBase:: |
|
CDNJS:: |
public | function |
Return all available version(s). Overrides CDNBase:: |
|
CDNJS:: |
public | function |
Overrides CDNBase:: |