3 namespace Drupal\Core\PhpStorage;
5 use Drupal\Core\Site\Settings;
6 use Drupal\Core\StreamWrapper\PublicStream;
9 * Creates a php storage object
11 class PhpStorageFactory {
14 * Instantiates a storage for generated PHP code.
16 * By default, this returns an instance of the
17 * \Drupal\Component\PhpStorage\MTimeProtectedFileStorage class.
19 * Classes implementing
20 * \Drupal\Component\PhpStorage\PhpStorageInterface can be registered for a
21 * specific bin or as a default implementation.
24 * The name for which the storage should be returned. Defaults to 'default'
25 * The name is also used as the storage bin if one is not specified in the
28 * @return \Drupal\Component\PhpStorage\PhpStorageInterface
29 * An instantiated storage for the specified name.
31 public static function get($name) {
33 $overrides = Settings::get('php_storage');
34 if (isset($overrides[$name])) {
35 $configuration = $overrides[$name];
37 elseif (isset($overrides['default'])) {
38 $configuration = $overrides['default'];
40 // Make sure all the necessary configuration values are set.
41 $class = isset($configuration['class']) ? $configuration['class'] : 'Drupal\Component\PhpStorage\MTimeProtectedFileStorage';
42 if (!isset($configuration['secret'])) {
43 $configuration['secret'] = Settings::getHashSalt();
45 if (!isset($configuration['bin'])) {
46 $configuration['bin'] = $name;
48 if (!isset($configuration['directory'])) {
49 $configuration['directory'] = PublicStream::basePath() . '/php';
51 return new $class($configuration);