You are here

class FileCacheFactory in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/lib/Drupal/Component/FileCache/FileCacheFactory.php \Drupal\Component\FileCache\FileCacheFactory

Creates a FileCache object.

Hierarchy

Expanded class hierarchy of FileCacheFactory

9 files declare their use of FileCacheFactory
DrupalKernel.php in core/lib/Drupal/Core/DrupalKernel.php
Contains \Drupal\Core\DrupalKernel.
ExtensionDiscovery.php in core/lib/Drupal/Core/Extension/ExtensionDiscovery.php
Contains \Drupal\Core\Extension\ExtensionDiscovery.
FileCacheFactoryTest.php in core/tests/Drupal/Tests/Component/FileCache/FileCacheFactoryTest.php
Contains \Drupal\Tests\Component\FileCache\FileCacheFactoryTest.
KernelTestBase.php in core/tests/Drupal/KernelTests/KernelTestBase.php
Contains \Drupal\KernelTests\KernelTestBase.
KernelTestBaseTest.php in core/tests/Drupal/KernelTests/KernelTestBaseTest.php
Contains \Drupal\KernelTests\KernelTestBaseTest.

... See full list

File

core/lib/Drupal/Component/FileCache/FileCacheFactory.php, line 13
Contains \Drupal\Component\FileCache\FileCacheFactory.

Namespace

Drupal\Component\FileCache
View source
class FileCacheFactory {

  /**
   * The configuration used to create FileCache objects.
   *
   * @var array $configuration
   */
  protected static $configuration;

  /**
   * The cache prefix.
   *
   * @var string
   */
  protected static $prefix;

  /**
   * Instantiates a FileCache object for a given collection identifier.
   *
   * @param string $collection
   *   The collection identifier for this FileCache.
   * @param array $default_configuration
   *   (optional) The default configuration for this FileCache collection. This
   *   can be used to e.g. specify default usage of a FileCache class.
   *
   * @return \Drupal\Component\FileCache\FileCacheInterface
   *   The initialized FileCache object.
   */
  public static function get($collection, $default_configuration = []) {
    $default_configuration += [
      'class' => '\\Drupal\\Component\\FileCache\\FileCache',
      'collection' => $collection,
      'cache_backend_class' => NULL,
      'cache_backend_configuration' => [],
    ];
    $configuration = [];
    if (isset(static::$configuration[$collection])) {
      $configuration = static::$configuration[$collection];
    }
    elseif (isset(static::$configuration['default'])) {
      $configuration = static::$configuration['default'];
    }

    // Add defaults to the configuration.
    $configuration = $configuration + $default_configuration;
    $class = $configuration['class'];
    return new $class(static::getPrefix(), $configuration['collection'], $configuration['cache_backend_class'], $configuration['cache_backend_configuration']);
  }

  /**
   * Gets the configuration used for constructing future file cache objects.
   *
   * @return array
   *   The configuration that is used.
   */
  public static function getConfiguration() {
    return static::$configuration;
  }

  /**
   * Sets the configuration to use for constructing future file cache objects.
   *
   * @param array $configuration
   *   The configuration to use.
   */
  public static function setConfiguration($configuration) {
    static::$configuration = $configuration;
  }

  /**
   * Returns the cache prefix.
   *
   * @return string
   *   The cache prefix.
   */
  public static function getPrefix() {
    return static::$prefix;
  }

  /**
   * Sets the cache prefix that should be used.
   *
   * Should be set to a secure, unique key to prevent cache pollution by a
   * third party.
   *
   * @param string $prefix
   *   The cache prefix.
   */
  public static function setPrefix($prefix) {
    static::$prefix = $prefix;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
FileCacheFactory::$configuration protected static property The configuration used to create FileCache objects.
FileCacheFactory::$prefix protected static property The cache prefix.
FileCacheFactory::get public static function Instantiates a FileCache object for a given collection identifier.
FileCacheFactory::getConfiguration public static function Gets the configuration used for constructing future file cache objects.
FileCacheFactory::getPrefix public static function Returns the cache prefix.
FileCacheFactory::setConfiguration public static function Sets the configuration to use for constructing future file cache objects.
FileCacheFactory::setPrefix public static function Sets the cache prefix that should be used.