You are here

class JSDelivr in Libraries CDN API 7

Same name and namespace in other branches
  1. 8 src/Plugin/LibrariesCdn/JsDelivr.php \Drupal\libraries_cdn\Plugin\LibrariesCdn\JSDelivr

Class JSDelivr.

Plugin annotation


@LibrariesCDNPlugin(
 id = "jsdelivr",
 description = "jsDelivr Integration",
 arguments = {
   "@drupal7"
 }
)

Hierarchy

  • class \Drupal\libraries_cdn\Type\CDNBase extends \Drupal\Component\Plugin\PluginBase implements CDNBaseInterface
    • class \Drupal\libraries_cdn\Plugin\LibrariesCDN\JSDelivr

Expanded class hierarchy of JSDelivr

1 file declares its use of JSDelivr
JSDelivrTest.php in tests/src/Plugin/LibrariesCDN/JSDelivrTest.php
Contains \Drupal\Tests\Libraries_cdn\Plugin\LibrariesCDN\JSDelivrTest.

File

src/Plugin/LibrariesCDN/JSDelivr.php, line 25
Plugin: jsDelivr.

Namespace

Drupal\libraries_cdn\Plugin\LibrariesCDN
View source
class JSDelivr 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.jsdelivr.com/v1/jsdelivr/libraries/%s',
      'getInformation' => 'http://api.jsdelivr.com/v1/jsdelivr/libraries?name=%s&fields=name,mainfile,lastversion,description,homepage,github,author',
      'getVersions' => 'http://api.jsdelivr.com/v1/jsdelivr/libraries?name=%s&fields=versions',
      'getFiles' => 'http://api.jsdelivr.com/v1/jsdelivr/libraries?name=%s&fields=assets',
      'search' => 'http://api.jsdelivr.com/v1/jsdelivr/libraries?name=*%s*',
      'convertFiles' => '//cdn.jsdelivr.net/%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;
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CDNBase::convertFiles public function
CDNBase::getConfiguration public function Return the configuration of the object. Overrides CDNBaseInterface::getConfiguration
CDNBase::getFiles public function Return all available file(s). Overrides CDNBaseInterface::getFiles 1
CDNBase::getInformation public function Get library information. Overrides CDNBaseInterface::getInformation 1
CDNBase::getLatestVersion public function Get latest version available of a library. Overrides CDNBaseInterface::getLatestVersion
CDNBase::getLibrary public function Get the library in use. Overrides CDNBaseInterface::getLibrary
CDNBase::getLocalCopy public function Copy a library from the CDN to the local filesystem. Overrides CDNBaseInterface::getLocalCopy
CDNBase::getLocalDirectoryName public function Get the local directory name of a library. Overrides CDNBaseInterface::getLocalDirectoryName
CDNBase::getLocalFileName public function Get the local file name of a library file. Overrides CDNBaseInterface::getLocalFileName
CDNBase::getScheme public function Get the default scheme. Overrides CDNBaseInterface::getScheme
CDNBase::getURL public function Get a particular URL. Overrides CDNBaseInterface::getURL
CDNBase::getURLs public function Get URLs. Overrides CDNBaseInterface::getURLs
CDNBase::getVersions public function Return all available version(s). Overrides CDNBaseInterface::getVersions 2
CDNBase::isAvailable public function Check if library is available. Overrides CDNBaseInterface::isAvailable 1
CDNBase::isLocalAvailable public function Check if a file is available locally. Overrides CDNBaseInterface::isLocalAvailable
CDNBase::query public function Request wrapper for querying a CDN. Overrides CDNBaseInterface::query
CDNBase::request public function Make an HTTP Request. Overrides CDNBaseInterface::request
CDNBase::search public function Perform a search for a library. Overrides CDNBaseInterface::search 1
CDNBase::setConfiguration public function Set the configuration of the object. Overrides CDNBaseInterface::setConfiguration
CDNBase::setLibrary public function Set the library to work with. Overrides CDNBaseInterface::setLibrary
CDNBase::setScheme public function Set default scheme for an url. Overrides CDNBaseInterface::setScheme
CDNBase::setURL public function Set a particular URL. Overrides CDNBaseInterface::setURL
CDNBase::setURLs public function Set URLs. Overrides CDNBaseInterface::setURLs
JSDelivr::formatData public function Return the data to use in each method. Overrides CDNBase::formatData
JSDelivr::__construct public function Overrides CDNBase::__construct