本文整理汇总了PHP中Drupal\Core\Site\Settings::get方法的典型用法代码示例。如果您正苦于以下问题:PHP Settings::get方法的具体用法?PHP Settings::get怎么用?PHP Settings::get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\Core\Site\Settings
的用法示例。
在下文中一共展示了Settings::get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: trustedHeadersAreSet
/**
* Tests that trusted header methods are called.
*
* \Symfony\Component\HttpFoundation\Request::setTrustedHeaderName() and
* \Symfony\Component\HttpFoundation\Request::setTrustedProxies() should
* always be called when reverse proxy settings are enabled.
*
* @param \Drupal\Core\Site\Settings $settings
* The settings object that holds reverse proxy configuration.
*/
protected function trustedHeadersAreSet(Settings $settings)
{
$middleware = new ReverseProxyMiddleware($this->mockHttpKernel, $settings);
$request = new Request();
$middleware->handle($request);
$this->assertSame($settings->get('reverse_proxy_header'), $request->getTrustedHeaderName($request::HEADER_CLIENT_IP));
$this->assertSame($settings->get('reverse_proxy_addresses'), $request->getTrustedProxies());
}
示例2: trustedHeadersAreSet
/**
* Tests that trusted header methods are called.
*
* \Symfony\Component\HttpFoundation\Request::setTrustedHeaderName() and
* \Symfony\Component\HttpFoundation\Request::setTrustedProxies() should
* always be called when reverse proxy settings are enabled.
*
* @param \Drupal\Core\Site\Settings $settings
* The settings object that holds reverse proxy configuration.
*/
protected function trustedHeadersAreSet(Settings $settings)
{
$subscriber = new ReverseProxySubscriber($settings);
$request = new Request();
$event = $this->getMockedEvent($request);
$subscriber->onKernelRequestReverseProxyCheck($event);
$this->assertSame($settings->get('reverse_proxy_header'), $request->getTrustedHeaderName($request::HEADER_CLIENT_IP));
$this->assertSame($settings->get('reverse_proxy_addresses'), $request->getTrustedProxies());
}
示例3: onKernelRequestReverseProxyCheck
/**
* Passes reverse proxy settings to current request.
*
* @param \Symfony\Component\HttpKernel\Event\GetResponseEvent $event
* The Event to process.
*/
public function onKernelRequestReverseProxyCheck(GetResponseEvent $event)
{
$request = $event->getRequest();
if ($this->settings->get('reverse_proxy', 0)) {
$reverse_proxy_header = $this->settings->get('reverse_proxy_header', 'HTTP_X_FORWARDED_FOR');
$request::setTrustedHeaderName($request::HEADER_CLIENT_IP, $reverse_proxy_header);
$reverse_proxy_addresses = $this->settings->get('reverse_proxy_addresses', array());
$request::setTrustedProxies($reverse_proxy_addresses);
}
}
示例4: get
/**
* {@inheritdoc}
*/
public function get($collection)
{
if (!isset($this->stores[$collection])) {
if ($service_name = $this->settings->get(static::SPECIFIC_PREFIX . $collection)) {
} elseif ($service_name = $this->settings->get(static::DEFAULT_SETTING)) {
} else {
$service_name = static::DEFAULT_SERVICE;
}
$this->stores[$collection] = $this->container->get($service_name)->get($collection);
}
return $this->stores[$collection];
}
示例5: get
/**
* Instantiates a cache backend class for a given cache bin.
*
* By default, this returns an instance of the
* Drupal\Core\Cache\DatabaseBackend class.
*
* Classes implementing Drupal\Core\Cache\CacheBackendInterface can register
* themselves both as a default implementation and for specific bins.
*
* @param string $bin
* The cache bin for which a cache backend object should be returned.
*
* @return \Drupal\Core\Cache\CacheBackendInterface
* The cache backend object associated with the specified bin.
*/
public function get($bin)
{
$cache_settings = $this->settings->get('cache');
if (isset($cache_settings['bins'][$bin])) {
$service_name = $cache_settings['bins'][$bin];
} elseif (isset($cache_settings['default'])) {
$service_name = $cache_settings['default'];
} else {
$service_name = 'cache.backend.database';
}
return $this->container->get($service_name)->get($bin);
}
示例6: execute
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new DrupalStyle($input, $output);
$settingKeys = array_keys($this->settings->getAll());
$io->newLine();
$io->info($this->trans('commands.config.settings.debug.messages.current'));
$io->newLine();
foreach ($settingKeys as $settingKey) {
$io->comment($settingKey, false);
$io->simple(Yaml::encode($this->settings->get($settingKey)));
}
$io->newLine();
}
示例7: handle
/**
* {@inheritdoc}
*/
public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = TRUE)
{
// Initialize proxy settings.
if ($this->settings->get('reverse_proxy', FALSE)) {
$reverse_proxy_header = $this->settings->get('reverse_proxy_header', 'X_FORWARDED_FOR');
$request::setTrustedHeaderName($request::HEADER_CLIENT_IP, $reverse_proxy_header);
$proxies = $this->settings->get('reverse_proxy_addresses', array());
if (count($proxies) > 0) {
$request::setTrustedProxies($proxies);
}
}
return $this->httpKernel->handle($request, $type, $catch);
}
示例8: testInstaller
/**
* Ensures that the user page is available after installation.
*/
public function testInstaller()
{
$this->assertUrl('user/1');
$this->assertResponse(200);
// Confirm that we are logged-in after installation.
$this->assertText($this->rootUser->getUsername());
// @todo hmmm this message is wrong!
// Verify that the confirmation message appears.
require_once \Drupal::root() . '/core/includes/install.inc';
$this->assertRaw(t('Congratulations, you installed @drupal!', array('@drupal' => drupal_install_profile_distribution_name())));
// Ensure that all modules, profile and themes have been installed and have
// expected weights.
$sync = \Drupal::service('config.storage.sync');
$sync_core_extension = $sync->read('core.extension');
$this->assertIdentical($sync_core_extension, \Drupal::config('core.extension')->get());
// Ensure that the correct install profile has been written to settings.php.
$listing = new ExtensionDiscovery(\Drupal::root());
$listing->setProfileDirectories([]);
$profiles = array_intersect_key($listing->scan('profile'), $sync_core_extension['module']);
$current_profile = Settings::get('install_profile');
$this->assertFalse(empty($current_profile), 'The $install_profile setting exists');
$this->assertEqual($current_profile, key($profiles));
// Test that any configuration entities in sync have been created.
// @todo
}
示例9: getToken
public static function getToken($user)
{
//@todo, check to see if we have a token stored for this user
$key = Settings::get('hash_salt');
$token = array("uid" => $user->id(), "mail" => $user->getEmail());
return \JWT::encode($token, $key);
}
示例10: register
/**
* {@inheritdoc}
*/
public function register(ContainerBuilder $container)
{
$this->registerUuid($container);
$this->registerTest($container);
// Only register the private file stream wrapper if a file path has been set.
if (Settings::get('file_private_path')) {
$container->register('stream_wrapper.private', 'Drupal\\Core\\StreamWrapper\\PrivateStream')->addTag('stream_wrapper', ['scheme' => 'private']);
}
// Add the compiler pass that lets service providers modify existing
// service definitions. This pass must come first so that later
// list-building passes are operating on the post-alter services list.
$container->addCompilerPass(new ModifyServiceDefinitionsPass());
$container->addCompilerPass(new BackendCompilerPass());
$container->addCompilerPass(new StackedKernelPass());
$container->addCompilerPass(new StackedSessionHandlerPass());
$container->addCompilerPass(new MainContentRenderersPass());
// Collect tagged handler services as method calls on consumer services.
$container->addCompilerPass(new TaggedHandlersPass());
$container->addCompilerPass(new RegisterStreamWrappersPass());
// Add a compiler pass for registering event subscribers.
$container->addCompilerPass(new RegisterKernelListenersPass(), PassConfig::TYPE_AFTER_REMOVING);
$container->addCompilerPass(new RegisterAccessChecksPass());
$container->addCompilerPass(new RegisterLazyRouteEnhancers());
$container->addCompilerPass(new RegisterLazyRouteFilters());
// Add a compiler pass for registering services needing destruction.
$container->addCompilerPass(new RegisterServicesForDestructionPass());
// Add the compiler pass that will process the tagged services.
$container->addCompilerPass(new ListCacheBinsPass());
$container->addCompilerPass(new CacheContextsPass());
// Register plugin managers.
$container->addCompilerPass(new PluginManagerPass());
$container->addCompilerPass(new DependencySerializationTraitPass());
}
示例11: testDrupalRewriteSettings
/**
* Tests the drupal_rewrite_settings() function.
*/
function testDrupalRewriteSettings()
{
include_once \Drupal::root() . '/core/includes/install.inc';
$site_path = $this->container->get('site.path');
$tests = array(array('original' => '$no_index_value_scalar = TRUE;', 'settings' => array('no_index_value_scalar' => (object) array('value' => FALSE, 'comment' => 'comment')), 'expected' => '$no_index_value_scalar = false; // comment'), array('original' => '$no_index_value_scalar = TRUE;', 'settings' => array('no_index_value_foo' => array('foo' => array('value' => (object) array('value' => NULL, 'required' => TRUE, 'comment' => 'comment')))), 'expected' => <<<'EXPECTED'
$no_index_value_scalar = TRUE;
$no_index_value_foo['foo']['value'] = NULL; // comment
EXPECTED
), array('original' => '$no_index_value_array = array("old" => "value");', 'settings' => array('no_index_value_array' => (object) array('value' => FALSE, 'required' => TRUE, 'comment' => 'comment')), 'expected' => '$no_index_value_array = array("old" => "value");
$no_index_value_array = false; // comment'), array('original' => '$has_index_value_scalar["foo"]["bar"] = NULL;', 'settings' => array('has_index_value_scalar' => array('foo' => array('bar' => (object) array('value' => FALSE, 'required' => TRUE, 'comment' => 'comment')))), 'expected' => '$has_index_value_scalar["foo"]["bar"] = false; // comment'), array('original' => '$has_index_value_scalar["foo"]["bar"] = "foo";', 'settings' => array('has_index_value_scalar' => array('foo' => array('value' => (object) array('value' => array('value' => 2), 'required' => TRUE, 'comment' => 'comment')))), 'expected' => <<<'EXPECTED'
$has_index_value_scalar["foo"]["bar"] = "foo";
$has_index_value_scalar['foo']['value'] = array (
'value' => 2,
); // comment
EXPECTED
));
foreach ($tests as $test) {
$filename = Settings::get('file_public_path', $site_path . '/files') . '/mock_settings.php';
file_put_contents(\Drupal::root() . '/' . $filename, "<?php\n" . $test['original'] . "\n");
drupal_rewrite_settings($test['settings'], $filename);
$this->assertEqual(file_get_contents(\Drupal::root() . '/' . $filename), "<?php\n" . $test['expected'] . "\n");
}
// Test that <?php gets added to the start of an empty settings file.
// Set the array of settings that will be written to the file.
$test = array('settings' => array('no_index' => (object) array('value' => TRUE, 'required' => TRUE)), 'expected' => '$no_index = true;');
// Make an empty file.
$filename = Settings::get('file_public_path', $site_path . '/files') . '/mock_settings.php';
file_put_contents(\Drupal::root() . '/' . $filename, "");
// Write the setting to the file.
drupal_rewrite_settings($test['settings'], $filename);
// Check that the result is just the php opening tag and the settings.
$this->assertEqual(file_get_contents(\Drupal::root() . '/' . $filename), "<?php\n" . $test['expected'] . "\n");
}
示例12: testOverwriteSelf
/**
* Copy a file onto itself.
*/
function testOverwriteSelf()
{
// Create a file for testing
$uri = $this->createUri();
// Copy the file onto itself with renaming works.
$new_filepath = file_unmanaged_copy($uri, $uri, FILE_EXISTS_RENAME);
$this->assertTrue($new_filepath, 'Copying onto itself with renaming works.');
$this->assertNotEqual($new_filepath, $uri, 'Copied file has a new name.');
$this->assertTrue(file_exists($uri), 'Original file exists after copying onto itself.');
$this->assertTrue(file_exists($new_filepath), 'Copied file exists after copying onto itself.');
$this->assertFilePermissions($new_filepath, Settings::get('file_chmod_file', FILE_CHMOD_FILE));
// Copy the file onto itself without renaming fails.
$new_filepath = file_unmanaged_copy($uri, $uri, FILE_EXISTS_ERROR);
$this->assertFalse($new_filepath, 'Copying onto itself without renaming fails.');
$this->assertTrue(file_exists($uri), 'File exists after copying onto itself.');
// Copy the file into same directory without renaming fails.
$new_filepath = file_unmanaged_copy($uri, drupal_dirname($uri), FILE_EXISTS_ERROR);
$this->assertFalse($new_filepath, 'Copying onto itself fails.');
$this->assertTrue(file_exists($uri), 'File exists after copying onto itself.');
// Copy the file into same directory with renaming works.
$new_filepath = file_unmanaged_copy($uri, drupal_dirname($uri), FILE_EXISTS_RENAME);
$this->assertTrue($new_filepath, 'Copying into same directory works.');
$this->assertNotEqual($new_filepath, $uri, 'Copied file has a new name.');
$this->assertTrue(file_exists($uri), 'Original file exists after copying onto itself.');
$this->assertTrue(file_exists($new_filepath), 'Copied file exists after copying onto itself.');
$this->assertFilePermissions($new_filepath, Settings::get('file_chmod_file', FILE_CHMOD_FILE));
}
示例13: testServicesYml
/**
* Tests services.yml in site directory.
*/
public function testServicesYml()
{
$container_yamls = Settings::get('container_yamls');
$container_yamls[] = $this->siteDirectory . '/services.yml';
$this->settingsSet('container_yamls', $container_yamls);
$this->assertFalse($this->container->has('site.service.yml'));
// A service provider class always has precedence over services.yml files.
// KernelTestBase::buildContainer() swaps out many services with in-memory
// implementations already, so those cannot be tested.
$this->assertIdentical(get_class($this->container->get('cache.backend.database')), 'Drupal\\Core\\Cache\\DatabaseBackendFactory');
$class = __CLASS__;
$doc = <<<EOD
services:
# Add a new service.
site.service.yml:
class: {$class}
# Swap out a core service.
cache.backend.database:
class: Drupal\\Core\\Cache\\MemoryBackendFactory
EOD;
file_put_contents($this->siteDirectory . '/services.yml', $doc);
// Rebuild the container.
$this->container->get('kernel')->rebuildContainer();
$this->assertTrue($this->container->has('site.service.yml'));
$this->assertIdentical(get_class($this->container->get('cache.backend.database')), 'Drupal\\Core\\Cache\\MemoryBackendFactory');
}
示例14: getAllFolders
/**
* Returns a map of all config object names and their folders.
*
* The list is based on enabled modules and themes. The active configuration
* storage is used rather than \Drupal\Core\Extension\ModuleHandler and
* \Drupal\Core\Extension\ThemeHandler in order to resolve circular
* dependencies between these services and \Drupal\Core\Config\ConfigInstaller
* and \Drupal\Core\Config\TypedConfigManager.
*
* @return array
* An array mapping config object names with directories.
*/
protected function getAllFolders()
{
if (!isset($this->folders)) {
$this->folders = array();
$this->folders += $this->getComponentNames('core', array('core'));
$extensions = $this->configStorage->read('core.extension');
if (!empty($extensions['module'])) {
$modules = $extensions['module'];
if (!$this->includeProfile) {
if ($install_profile = Settings::get('install_profile')) {
unset($modules[$install_profile]);
}
}
$this->folders += $this->getComponentNames('module', array_keys($modules));
}
if (!empty($extensions['theme'])) {
$this->folders += $this->getComponentNames('theme', array_keys($extensions['theme']));
}
// The install profile can override module default configuration. We do
// this by replacing the config file path from the module/theme with the
// install profile version if there are any duplicates.
$profile_folders = $this->getComponentNames('profile', array(drupal_get_profile()));
$folders_to_replace = array_intersect_key($profile_folders, $this->folders);
if (!empty($folders_to_replace)) {
$this->folders = array_merge($this->folders, $folders_to_replace);
}
}
return $this->folders;
}
示例15: testNormal
/**
* Move a normal file.
*/
function testNormal()
{
// Create a file for testing
$uri = $this->createUri();
// Moving to a new name.
$desired_filepath = 'public://' . $this->randomMachineName();
$new_filepath = file_unmanaged_move($uri, $desired_filepath, FILE_EXISTS_ERROR);
$this->assertTrue($new_filepath, 'Move was successful.');
$this->assertEqual($new_filepath, $desired_filepath, 'Returned expected filepath.');
$this->assertTrue(file_exists($new_filepath), 'File exists at the new location.');
$this->assertFalse(file_exists($uri), 'No file remains at the old location.');
$this->assertFilePermissions($new_filepath, Settings::get('file_chmod_file', FILE_CHMOD_FILE));
// Moving with rename.
$desired_filepath = 'public://' . $this->randomMachineName();
$this->assertTrue(file_exists($new_filepath), 'File exists before moving.');
$this->assertTrue(file_put_contents($desired_filepath, ' '), 'Created a file so a rename will have to happen.');
$newer_filepath = file_unmanaged_move($new_filepath, $desired_filepath, FILE_EXISTS_RENAME);
$this->assertTrue($newer_filepath, 'Move was successful.');
$this->assertNotEqual($newer_filepath, $desired_filepath, 'Returned expected filepath.');
$this->assertTrue(file_exists($newer_filepath), 'File exists at the new location.');
$this->assertFalse(file_exists($new_filepath), 'No file remains at the old location.');
$this->assertFilePermissions($newer_filepath, Settings::get('file_chmod_file', FILE_CHMOD_FILE));
// TODO: test moving to a directory (rather than full directory/file path)
// TODO: test creating and moving normal files (rather than streams)
}