You are here

class Extension in Zircon Profile 8

Same name in this branch
  1. 8 vendor/symfony/http-kernel/DependencyInjection/Extension.php \Symfony\Component\HttpKernel\DependencyInjection\Extension
  2. 8 vendor/symfony/dependency-injection/Extension/Extension.php \Symfony\Component\DependencyInjection\Extension\Extension
  3. 8 core/lib/Drupal/Core/Extension/Extension.php \Drupal\Core\Extension\Extension
Same name and namespace in other branches
  1. 8.0 core/lib/Drupal/Core/Extension/Extension.php \Drupal\Core\Extension\Extension

Defines an extension (file) object.

Hierarchy

  • class \Drupal\Core\Extension\Extension implements \Drupal\Core\Extension\Serializable

Expanded class hierarchy of Extension

25 files declare their use of Extension
config_translation_test.module in core/modules/config_translation/tests/modules/config_translation_test/config_translation_test.module
Configuration Translation Test module.
FieldDefinitionIntegrityTest.php in core/modules/field/src/Tests/FieldDefinitionIntegrityTest.php
Contains \Drupal\field\Tests\FieldDefinitionIntegrityTest.
InstallStorage.php in core/lib/Drupal/Core/Config/InstallStorage.php
Contains \Drupal\Core\Config\InstallStorage.
locale_test.module in core/modules/locale/tests/modules/locale_test/locale_test.module
Simulate a custom module with a local po file.
locale_test_development_release.module in core/modules/locale/tests/modules/locale_test_development_release/locale_test_development_release.module
Simulate a Drupal version.

... See full list

5 string references to 'Extension'
Bundle::getContainerExtensionClass in vendor/symfony/http-kernel/Bundle/Bundle.php
Returns the bundle's container extension class.
ConvertImageEffect::buildConfigurationForm in core/modules/image/src/Plugin/ImageEffect/ConvertImageEffect.php
Form constructor.
Extension::getAlias in vendor/symfony/dependency-injection/Extension/Extension.php
Returns the recommended alias to use in XML.
FileViewsData::getViewsData in core/modules/file/src/FileViewsData.php
Returns views data for the entity type.
image.schema.yml in core/modules/image/config/schema/image.schema.yml
core/modules/image/config/schema/image.schema.yml

File

core/lib/Drupal/Core/Extension/Extension.php, line 13
Contains \Drupal\Core\Extension\Extension.

Namespace

Drupal\Core\Extension
View source
class Extension implements \Serializable {

  /**
   * The type of the extension (e.g., 'module').
   *
   * @var string
   */
  protected $type;

  /**
   * The relative pathname of the extension (e.g., 'core/modules/node/node.info.yml').
   *
   * @var string
   */
  protected $pathname;

  /**
   * The filename of the main extension file (e.g., 'node.module').
   *
   * @var string|null
   */
  protected $filename;

  /**
   * An SplFileInfo instance for the extension's info file.
   *
   * Note that SplFileInfo is a PHP resource and resources cannot be serialized.
   *
   * @var \SplFileInfo
   */
  protected $splFileInfo;

  /**
   * The app root.
   *
   * @var string
   */
  protected $root;

  /**
   * Constructs a new Extension object.
   *
   * @param string $root
   *   The app root.
   * @param string $type
   *   The type of the extension; e.g., 'module'.
   * @param string $pathname
   *   The relative path and filename of the extension's info file; e.g.,
   *   'core/modules/node/node.info.yml'.
   * @param string $filename
   *   (optional) The filename of the main extension file; e.g., 'node.module'.
   */
  public function __construct($root, $type, $pathname, $filename = NULL) {
    $this->root = $root;
    $this->type = $type;
    $this->pathname = $pathname;
    $this->filename = $filename;
  }

  /**
   * Returns the type of the extension.
   *
   * @return string
   */
  public function getType() {
    return $this->type;
  }

  /**
   * Returns the internal name of the extension.
   *
   * @return string
   */
  public function getName() {
    return basename($this->pathname, '.info.yml');
  }

  /**
   * Returns the relative path of the extension.
   *
   * @return string
   */
  public function getPath() {
    return dirname($this->pathname);
  }

  /**
   * Returns the relative path and filename of the extension's info file.
   *
   * @return string
   */
  public function getPathname() {
    return $this->pathname;
  }

  /**
   * Returns the filename of the extension's info file.
   *
   * @return string
   */
  public function getFilename() {
    return basename($this->pathname);
  }

  /**
   * Returns the relative path of the main extension file, if any.
   *
   * @return string|null
   */
  public function getExtensionPathname() {
    if ($this->filename) {
      return $this
        ->getPath() . '/' . $this->filename;
    }
  }

  /**
   * Returns the name of the main extension file, if any.
   *
   * @return string|null
   */
  public function getExtensionFilename() {
    return $this->filename;
  }

  /**
   * Loads the main extension file, if any.
   *
   * @return bool
   *   TRUE if this extension has a main extension file, FALSE otherwise.
   */
  public function load() {
    if ($this->filename) {
      include_once $this->root . '/' . $this
        ->getPath() . '/' . $this->filename;
      return TRUE;
    }
    return FALSE;
  }

  /**
   * Re-routes method calls to SplFileInfo.
   *
   * Offers all SplFileInfo methods to consumers; e.g., $extension->getMTime().
   */
  public function __call($method, array $args) {
    if (!isset($this->splFileInfo)) {
      $this->splFileInfo = new \SplFileInfo($this->pathname);
    }
    return call_user_func_array(array(
      $this->splFileInfo,
      $method,
    ), $args);
  }

  /**
   * Implements Serializable::serialize().
   *
   * Serializes the Extension object in the most optimized way.
   */
  public function serialize() {

    // Don't serialize the app root, since this could change if the install is
    // moved.
    $data = array(
      'type' => $this->type,
      'pathname' => $this->pathname,
      'filename' => $this->filename,
    );

    // @todo ThemeHandler::listInfo(), ThemeHandler::rebuildThemeData(), and
    //   system_list() are adding custom properties to the Extension object.
    $info = new \ReflectionObject($this);
    foreach ($info
      ->getProperties(\ReflectionProperty::IS_PUBLIC) as $property) {
      $data[$property
        ->getName()] = $property
        ->getValue($this);
    }
    return serialize($data);
  }

  /**
   * {@inheritdoc}
   */
  public function unserialize($data) {
    $data = unserialize($data);

    // Get the app root from the container.
    $this->root = DRUPAL_ROOT;
    $this->type = $data['type'];
    $this->pathname = $data['pathname'];
    $this->filename = $data['filename'];

    // @todo ThemeHandler::listInfo(), ThemeHandler::rebuildThemeData(), and
    //   system_list() are adding custom properties to the Extension object.
    foreach ($data as $property => $value) {
      if (!isset($this->{$property})) {
        $this->{$property} = $value;
      }
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Extension::$filename protected property The filename of the main extension file (e.g., 'node.module').
Extension::$pathname protected property The relative pathname of the extension (e.g., 'core/modules/node/node.info.yml').
Extension::$root protected property The app root.
Extension::$splFileInfo protected property An SplFileInfo instance for the extension's info file.
Extension::$type protected property The type of the extension (e.g., 'module').
Extension::getExtensionFilename public function Returns the name of the main extension file, if any.
Extension::getExtensionPathname public function Returns the relative path of the main extension file, if any.
Extension::getFilename public function Returns the filename of the extension's info file.
Extension::getName public function Returns the internal name of the extension.
Extension::getPath public function Returns the relative path of the extension.
Extension::getPathname public function Returns the relative path and filename of the extension's info file.
Extension::getType public function Returns the type of the extension.
Extension::load public function Loads the main extension file, if any.
Extension::serialize public function Implements Serializable::serialize().
Extension::unserialize public function
Extension::__call public function Re-routes method calls to SplFileInfo.
Extension::__construct public function Constructs a new Extension object.