class Dummy in Libraries CDN API 7
Class Dummy.
Plugin annotation
@LibrariesCDNPlugin(
id = "dummy",
description = "Dummy CDN",
arguments = {
"@drupal7"
}
)
Hierarchy
- class \Drupal\libraries_cdn\Type\CDNBase extends \Drupal\Component\Plugin\PluginBase implements CDNBaseInterface
- class \Drupal\libraries_cdn_example_plugin\Plugin\LibrariesCDN\Dummy
Expanded class hierarchy of Dummy
File
- modules/
libraries_cdn_example_plugin/ src/ Plugin/ LibrariesCDN/ Dummy.php, line 25 - Plugin: jsDelivr.
Namespace
Drupal\libraries_cdn_example_plugin\Plugin\LibrariesCDNView source
class Dummy extends CDNBase {
/**
* {@inheritdoc}
*/
public function __construct(array $configuration, $plugin_id, array $plugin_definition, Drupal7 $drupal7) {
if (empty($configuration['urls'])) {
$configuration['urls'] = array();
}
$converFileUrl = url('libraries_cdn/dummy/files', array(
'absolute' => TRUE,
));
$converFileUrl = parse_url($converFileUrl);
array_shift($converFileUrl);
$converFileUrl = implode($converFileUrl);
$configuration['urls'] += array(
'convertFiles' => '//' . $converFileUrl . '/%s/%s/',
);
parent::__construct($configuration, $plugin_id, $plugin_definition, $drupal7);
}
/**
* {@inheritdoc}
*/
public function formatData($function, array $data = array()) {
switch ($function) {
case 'getVersions':
return isset($data[0]) && isset($data[0]['versions']) ? $data[0]['versions'] : array();
case 'getFiles':
return isset($data[0]) && isset($data[0]['assets']) ? $data[0]['assets'] : array();
case 'getLatestVersion':
return isset($data['lastversion']) ? $data['lastversion'] : NULL;
case 'getInformation':
return isset($data[0]) ? $data[0] : array();
default:
return $data;
}
}
/**
* {@inheritdoc}
*/
public function search($library) {
$this
->setLibrary($library);
return array(
0 => array(
'name' => drupal_html_class(drupal_clean_css_identifier($library)),
),
);
}
/**
* {@inheritdoc}
*/
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)));
}
/**
* {@inheritdoc}
*/
public function getVersions() {
$data = array();
$count_version = mt_rand(1, 5);
for ($i = 0; $i < $count_version; $i++) {
$major = mt_rand(1, 10);
$minor = mt_rand(1, 1000);
$data['versions'][] = $major . '.' . $minor;
}
return array_filter($data);
}
/**
* {@inheritdoc}
*/
public function isAvailable() {
return TRUE;
}
/**
* {@inheritdoc}
*/
public function getInformation() {
return array(
array(
'name' => 'dummy',
'mainfile' => 'jquery.min.js',
'lastversion' => '3.0.0-alpha1',
'description' => 'jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. jQuery is designed to change the way that you write JavaScript.',
'homepage' => 'http://jquery.com/',
'github' => 'https://github.com/jquery/jquery',
'author' => 'jQuery Foundation',
),
);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CDNBase:: |
public | function | ||
CDNBase:: |
public | function |
Return the configuration of the object. Overrides CDNBaseInterface:: |
|
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 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 |
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:: |
|
Dummy:: |
public | function |
Return the data to use in each method. Overrides CDNBase:: |
|
Dummy:: |
public | function |
Return all available file(s). Overrides CDNBase:: |
|
Dummy:: |
public | function |
Get library information. Overrides CDNBase:: |
|
Dummy:: |
public | function |
Return all available version(s). Overrides CDNBase:: |
|
Dummy:: |
public | function |
Check if library is available. Overrides CDNBase:: |
|
Dummy:: |
public | function |
Perform a search for a library. Overrides CDNBase:: |
|
Dummy:: |
public | function |
Overrides CDNBase:: |