You are here

class CDNJS in Libraries CDN API 7

Same name and namespace in other branches
  1. 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\LibrariesCDN
View 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

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::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
CDNJS::formatData public function Return the data to use in each method. Overrides CDNBase::formatData
CDNJS::getVersions public function Return all available version(s). Overrides CDNBase::getVersions
CDNJS::__construct public function Overrides CDNBase::__construct