Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 22 |
PhpStorageFactory | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
42 | |
0.00% |
0 / 22 |
get | |
0.00% |
0 / 1 |
42 | |
0.00% |
0 / 22 |
<?php | |
/** | |
* @file | |
* Contains \Drupal\Core\PhpStorage\PhpStorageFactory. | |
*/ | |
namespace Drupal\Core\PhpStorage; | |
use Drupal\Core\Site\Settings; | |
use Drupal\Core\StreamWrapper\PublicStream; | |
/** | |
* Creates a php storage object | |
*/ | |
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. | |
*/ | |
static function get($name) { | |
$overrides = Settings::get('php_storage'); | |
if (isset($overrides[$name])) { | |
$configuration = $overrides[$name]; | |
} | |
elseif (isset($overrides['default'])) { | |
$configuration = $overrides['default']; | |
} | |
else { | |
$configuration = array( | |
'class' => 'Drupal\Component\PhpStorage\MTimeProtectedFileStorage', | |
'secret' => Settings::getHashSalt(), | |
); | |
} | |
$class = isset($configuration['class']) ? $configuration['class'] : 'Drupal\Component\PhpStorage\MTimeProtectedFileStorage'; | |
if (!isset($configuration['bin'])) { | |
$configuration['bin'] = $name; | |
} | |
if (!isset($configuration['directory'])) { | |
$configuration['directory'] = PublicStream::basePath() . '/php'; | |
} | |
return new $class($configuration); | |
} | |
} |