class PhpStorageFactory

Creates a php storage object

Hierarchy

Expanded class hierarchy of PhpStorageFactory

5 files declare their use of PhpStorageFactory
common.inc in drupal/core/includes/common.inc
Common functions that many Drupal modules will need to reference.
DrupalKernel.php in drupal/core/lib/Drupal/Core/DrupalKernel.php
Definition of Drupal\Core\DrupalKernel.
MTimeProtectedFileStorageTest.php in drupal/core/modules/system/lib/Drupal/system/Tests/PhpStorage/MTimeProtectedFileStorageTest.php
Definition of Drupal\system\Tests\PhpStorage\MTimeProtectedFileStorageTest.
PhpStorageTestBase.php in drupal/core/modules/system/lib/Drupal/system/Tests/PhpStorage/PhpStorageTestBase.php
Definition of Drupal\system\Tests\PhpStorage\PhpStorageTestBase.
TwigEnvironment.php in drupal/core/lib/Drupal/Core/Template/TwigEnvironment.php
Definition of Drupal\Core\Template\TwigEnvironment.

File

drupal/core/lib/Drupal/Component/PhpStorage/PhpStorageFactory.php, line 13
Definition of Drupal\Component\PhpStorage\PhpStorageFactory.

Namespace

Drupal\Component\PhpStorage
View source
class PhpStorageFactory {

  /**
   * Instantiates a storage controller 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 controller 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 controller for the specified name.
   */
  static function get($name) {
    global $conf;
    if (isset($conf['php_storage'][$name])) {
      $configuration = $conf['php_storage'][$name];
    }
    elseif (isset($conf['php_storage']['default'])) {
      $configuration = $conf['php_storage']['default'];
    }
    else {
      $configuration = array(
        'class' => 'Drupal\\Component\\PhpStorage\\MTimeProtectedFileStorage',
        'secret' => $GLOBALS['drupal_hash_salt'],
      );
    }
    $class = isset($configuration['class']) ? $configuration['class'] : 'Drupal\\Component\\PhpStorage\\MTimeProtectedFileStorage';
    if (!isset($configuration['bin'])) {
      $configuration['bin'] = $name;
    }
    if (!isset($configuration['directory'])) {
      $path = isset($conf['file_public_path']) ? $conf['file_public_path'] : conf_path() . '/files';
      $configuration['directory'] = DRUPAL_ROOT . "/{$path}/php";
    }
    return new $class($configuration);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
PhpStorageFactory::get static function Instantiates a storage controller for generated PHP code.