class PhpStorageFactory

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/PhpStorage/PhpStorageFactory.php \Drupal\Core\PhpStorage\PhpStorageFactory
  2. 8.9.x core/lib/Drupal/Core/PhpStorage/PhpStorageFactory.php \Drupal\Core\PhpStorage\PhpStorageFactory
  3. 10 core/lib/Drupal/Core/PhpStorage/PhpStorageFactory.php \Drupal\Core\PhpStorage\PhpStorageFactory

Creates a php storage object.

Hierarchy

Expanded class hierarchy of PhpStorageFactory

5 files declare their use of PhpStorageFactory
PhpBackend.php in core/lib/Drupal/Core/Cache/PhpBackend.php
PhpStorageFactoryTest.php in core/modules/system/tests/src/Kernel/PhpStorage/PhpStorageFactoryTest.php
TwigEnvironment.php in core/lib/Drupal/Core/Template/TwigEnvironment.php
TwigPhpStorageCache.php in core/lib/Drupal/Core/Template/TwigPhpStorageCache.php
TwigSettingsTest.php in core/modules/system/tests/src/Functional/Theme/TwigSettingsTest.php

File

core/lib/Drupal/Core/PhpStorage/PhpStorageFactory.php, line 11

Namespace

Drupal\Core\PhpStorage
View source
class PhpStorageFactory {
    
    /**
     * Instantiates a storage for generated PHP code.
     *
     * By default, this returns an instance of the
     * \Drupal\Component\PhpStorage\MTimeProtectedFileStorage class.
     *
     * Classes implementing
     * \Drupal\Component\PhpStorage\PhpStorageInterface can be registered for a
     * specific bin or as a default implementation.
     *
     * @param string $name
     *   The name for which the storage should be returned. Defaults to 'default'
     *   The name is also used as the storage bin if one is not specified in the
     *   configuration.
     *
     * @return \Drupal\Component\PhpStorage\PhpStorageInterface
     *   An instantiated storage for the specified name.
     */
    public static function get($name) {
        $configuration = [];
        $overrides = Settings::get('php_storage');
        if (isset($overrides[$name])) {
            $configuration = $overrides[$name];
        }
        elseif (isset($overrides['default'])) {
            $configuration = $overrides['default'];
        }
        // Make sure all the necessary configuration values are set.
        $class = $configuration['class'] ?? 'Drupal\\Component\\PhpStorage\\MTimeProtectedFileStorage';
        if (!isset($configuration['secret'])) {
            $configuration['secret'] = Settings::getHashSalt();
        }
        if (!isset($configuration['bin'])) {
            $configuration['bin'] = $name;
        }
        if (!isset($configuration['directory'])) {
            $configuration['directory'] = PublicStream::basePath() . '/php';
        }
        return new $class($configuration);
    }

}

Members

Title Sort descending Modifiers Object type Summary
PhpStorageFactory::get public static function Instantiates a storage for generated PHP code.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.