You are here

trait FeatureDetectionTrait in Markdown 8.2

Trait for implementing feature detection.

@todo Move upstream to https://www.drupal.org/project/installable_plugins.

Hierarchy

2 files declare their use of FeatureDetectionTrait
SmartPunctuationExtension.php in src/Plugin/Markdown/CommonMark/Extension/SmartPunctuationExtension.php
TableOfContentsExtension.php in src/Plugin/Markdown/CommonMark/Extension/TableOfContentsExtension.php

File

src/Traits/FeatureDetectionTrait.php, line 12

Namespace

Drupal\markdown\Traits
View source
trait FeatureDetectionTrait {

  /**
   * An array of test features.
   *
   * @var array
   *   An associative array of booleans where the key is the feature name.
   */
  protected static $features = [];

  /**
   * Determines whether a feature exists.
   *
   * @param string $name
   *   The name of the feature. This name will be converted into a camel case
   *   version with "feature" as the prefix (i.e. name => featureName). This
   *   will be used to look for a static method on the object this trait is
   *   used in. If found, it will be invoked and cast to a boolean value.
   *
   * @return bool
   *   TRUE or FALSE
   */
  protected static function featureExists($name) {
    if (!isset(static::$features[$name])) {
      $class = static::class;
      $method = (new CamelCaseToSnakeCaseNameConverter())
        ->denormalize("feature_{$name}");
      static::$features[$name] = method_exists($class, $method) ? !!$class::$method() : FALSE;
    }
    return static::$features[$name];
  }

}

Members

Namesort descending Modifiers Type Description Overrides
FeatureDetectionTrait::$features protected static property An array of test features.
FeatureDetectionTrait::featureExists protected static function Determines whether a feature exists.