本文整理汇总了PHP中config_get_config_directory函数的典型用法代码示例。如果您正苦于以下问题:PHP config_get_config_directory函数的具体用法?PHP config_get_config_directory怎么用?PHP config_get_config_directory使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了config_get_config_directory函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testInstaller
/**
* Ensures that the user page is available after installation.
*/
public function testInstaller()
{
// Do assertions from parent.
parent::testInstaller();
// Do assertions specific to test.
$this->assertEqual(drupal_realpath($this->sync_dir), config_get_config_directory(CONFIG_SYNC_DIRECTORY), 'The sync directory has been updated during the installation.');
$this->assertEqual(USER_REGISTER_ADMINISTRATORS_ONLY, \Drupal::config('user.settings')->get('register'), 'Ensure standard_install() does not overwrite user.settings::register.');
$this->assertEqual([], \Drupal::entityDefinitionUpdateManager()->getChangeSummary(), 'There are no entity or field definition updates.');
}
示例2: execute
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new DrupalStyle($input, $output);
$directory = $input->getOption('directory');
$tar = $input->getOption('tar');
$removeUuid = $input->getOption('remove-uuid');
if (!$directory) {
$directory = config_get_config_directory(CONFIG_SYNC_DIRECTORY);
}
if ($tar) {
if (!is_dir($directory)) {
mkdir($directory, 0777, true);
}
$dateTime = new \DateTime();
$archiveFile = sprintf('%s/config-%s.tar.gz', $directory, $dateTime->format('Y-m-d-H-i-s'));
$archiveTar = new ArchiveTar($archiveFile, 'gz');
}
try {
// Get raw configuration data without overrides.
foreach ($this->configManager->getConfigFactory()->listAll() as $name) {
$configData = $this->configManager->getConfigFactory()->get($name)->getRawData();
$configName = sprintf('%s.yml', $name);
// The _core is site-specific, so don't export it.
unset($configData['_core']);
if ($removeUuid) {
unset($configData['uuid']);
}
$ymlData = Yaml::encode($configData);
if ($tar) {
$archiveTar->addString($configName, $ymlData);
continue;
}
$configFileName = sprintf('%s/%s', $directory, $configName);
$fileSystem = new Filesystem();
try {
$fileSystem->mkdir($directory);
} catch (IOExceptionInterface $e) {
$io->error(sprintf($this->trans('commands.config.export.messages.error'), $e->getPath()));
}
file_put_contents($configFileName, $ymlData);
}
} catch (\Exception $e) {
$io->error($e->getMessage());
}
$io->info(sprintf($this->trans('commands.config.export.messages.directory'), $directory));
}
示例3: execute
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new DrupalStyle($input, $output);
$directory = $input->getOption('directory');
if ($directory) {
$configSyncDir = $directory;
} else {
$configSyncDir = config_get_config_directory(CONFIG_SYNC_DIRECTORY);
}
$source_storage = new FileStorage($configSyncDir);
$storage_comparer = new StorageComparer($source_storage, $this->configStorage, $this->configManager);
if (!$storage_comparer->createChangelist()->hasChanges()) {
$io->success($this->trans('commands.config.import.messages.nothing-to-do'));
}
if ($this->configImport($io, $storage_comparer)) {
$io->success($this->trans('commands.config.import.messages.imported'));
}
}
示例4: testImportCreate
/**
* Tests creating a content type during config import.
*/
public function testImportCreate()
{
$node_type_id = 'import';
$node_type_config_name = "node.type.{$node_type_id}";
// Simulate config data to import.
$active = $this->container->get('config.storage');
$sync = $this->container->get('config.storage.sync');
$this->copyConfig($active, $sync);
// Manually add new node type.
$src_dir = __DIR__ . '/../../../modules/node_test_config/sync';
$target_dir = config_get_config_directory(CONFIG_SYNC_DIRECTORY);
$this->assertTrue(file_unmanaged_copy("{$src_dir}/{$node_type_config_name}.yml", "{$target_dir}/{$node_type_config_name}.yml"));
// Import the content of the sync directory.
$this->configImporter()->import();
// Check that the content type was created.
$node_type = NodeType::load($node_type_id);
$this->assertTrue($node_type, 'Import node type from sync was created.');
$this->assertFalse(FieldConfig::loadByName('node', $node_type_id, 'body'));
}
示例5: submitForm
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state)
{
if ($path = $form_state->getValue('import_tarball')) {
$this->configStorage->deleteAll();
try {
$archiver = new ArchiveTar($path, 'gz');
$files = array();
foreach ($archiver->listContent() as $file) {
$files[] = $file['filename'];
}
$archiver->extractList($files, config_get_config_directory(CONFIG_STAGING_DIRECTORY));
drupal_set_message($this->t('Your configuration files were successfully uploaded, ready for import.'));
$form_state->setRedirect('config.sync');
} catch (\Exception $e) {
drupal_set_message($this->t('Could not extract the contents of the tar file. The error message is <em>@message</em>', array('@message' => $e->getMessage())), 'error');
}
drupal_unlink($path);
}
}
示例6: execute
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$config_file = $input->getArgument('config-file');
$copy_only = $input->getOption('copy-only');
try {
$files = array();
$archiver = new ArchiveTar($config_file, 'gz');
$output->writeln($this->trans('commands.config.import.messages.config_files_imported'));
foreach ($archiver->listContent() as $file) {
$pathinfo = pathinfo($file['filename']);
$files[$pathinfo['filename']] = $file['filename'];
$output->writeln('[-] <info>' . $file['filename'] . '</info>');
}
$config_staging_dir = config_get_config_directory(CONFIG_SYNC_DIRECTORY);
try {
$archiver->extract($config_staging_dir . '/');
} catch (\Exception $e) {
$output->writeln('[+] <error>' . $e->getMessage() . '</error>');
return;
}
if ($copy_only) {
$output->writeln(sprintf($this->trans('commands.config.import.messages.copied'), CONFIG_SYNC_DIRECTORY));
} else {
foreach ($files as $cofig_name => $filename) {
$config = $this->getConfigFactory()->getEditable($cofig_name);
$parser = new Parser();
$config_value = $parser->parse(file_get_contents($config_staging_dir . '/' . $filename));
$config->setData($config_value);
try {
$config->save();
} catch (\Exception $e) {
$output->writeln('[+] <error>' . $e->getMessage() . '</error>');
return;
}
}
$output->writeln(sprintf($this->trans('commands.config.import.messages.imported'), CONFIG_SYNC_DIRECTORY));
}
} catch (\Exception $e) {
$output->writeln('[+] <error>' . $e->getMessage() . '</error>');
return;
}
}
示例7: testImport
/**
* Tests importing configuration.
*/
function testImport()
{
// Verify access to the config upload form.
$this->drupalGet('admin/config/development/configuration/full/import');
$this->assertResponse(200);
// Attempt to upload a non-tar file.
$text_file = current($this->drupalGetTestFiles('text'));
$edit = array('files[import_tarball]' => drupal_realpath($text_file->uri));
$this->drupalPostForm('admin/config/development/configuration/full/import', $edit, t('Upload'));
$this->assertText(t('Could not extract the contents of the tar file'));
// Make the sync directory read-only.
$directory = config_get_config_directory(CONFIG_SYNC_DIRECTORY);
\Drupal::service('file_system')->chmod($directory, 0555);
$this->drupalGet('admin/config/development/configuration/full/import');
$this->assertRaw(t('The directory %directory is not writable.', ['%directory' => $directory]));
// Ensure submit button for \Drupal\config\Form\ConfigImportForm is
// disabled.
$submit_is_disabled = $this->cssSelect('form.config-import-form input[type="submit"]:disabled');
$this->assertTrue(count($submit_is_disabled) === 1, 'The submit button is disabled.');
}
示例8: execute
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new DrupalStyle($input, $output);
$configFile = $input->getOption('file');
$removeFiles = $input->getOption('remove-files');
$configSyncDir = config_get_config_directory(CONFIG_SYNC_DIRECTORY);
if ($configFile) {
$archiveTar = new ArchiveTar($configFile, 'gz');
$io->simple($this->trans('commands.config.import.messages.config_files_imported'));
foreach ($archiveTar->listContent() as $file) {
$io->info('[-] ' . $file['filename']);
}
try {
$archiveTar->extract($configSyncDir . '/');
} catch (\Exception $e) {
$io->error($e->getMessage());
return;
}
}
$finder = new Finder();
$finder->in($configSyncDir);
$finder->name("*.yml");
foreach ($finder as $configFile) {
$configName = $configFile->getBasename('.yml');
$configFilePath = sprintf('%s/%s', $configSyncDir, $configFile->getBasename());
$config = $this->getConfigFactory()->getEditable($configName);
$parser = new Parser();
$configData = $parser->parse(file_get_contents($configFilePath));
$config->setData($configData);
if ($removeFiles) {
file_unmanaged_delete($configFilePath);
}
try {
$config->save();
} catch (\Exception $e) {
$io->error($e->getMessage());
return;
}
}
$io->success(sprintf($this->trans('commands.config.import.messages.imported'), CONFIG_SYNC_DIRECTORY));
}
示例9: testImportCreate
/**
* Tests creating field storages and fields during config import.
*/
function testImportCreate()
{
// A field storage with one single field.
$field_name = 'field_test_import_sync';
$field_storage_id = "entity_test.{$field_name}";
$field_id = "entity_test.entity_test.{$field_name}";
$field_storage_config_name = "field.storage.{$field_storage_id}";
$field_config_name = "field.field.{$field_id}";
// A field storage with two fields.
$field_name_2 = 'field_test_import_sync_2';
$field_storage_id_2 = "entity_test.{$field_name_2}";
$field_id_2a = "entity_test.test_bundle.{$field_name_2}";
$field_id_2b = "entity_test.test_bundle_2.{$field_name_2}";
$field_storage_config_name_2 = "field.storage.{$field_storage_id_2}";
$field_config_name_2a = "field.field.{$field_id_2a}";
$field_config_name_2b = "field.field.{$field_id_2b}";
$active = $this->container->get('config.storage');
$sync = $this->container->get('config.storage.sync');
$this->copyConfig($active, $sync);
// Add the new files to the sync directory.
$src_dir = __DIR__ . '/../../modules/field_test_config/sync';
$target_dir = config_get_config_directory(CONFIG_SYNC_DIRECTORY);
$this->assertTrue(file_unmanaged_copy("{$src_dir}/{$field_storage_config_name}.yml", "{$target_dir}/{$field_storage_config_name}.yml"));
$this->assertTrue(file_unmanaged_copy("{$src_dir}/{$field_config_name}.yml", "{$target_dir}/{$field_config_name}.yml"));
$this->assertTrue(file_unmanaged_copy("{$src_dir}/{$field_storage_config_name_2}.yml", "{$target_dir}/{$field_storage_config_name_2}.yml"));
$this->assertTrue(file_unmanaged_copy("{$src_dir}/{$field_config_name_2a}.yml", "{$target_dir}/{$field_config_name_2a}.yml"));
$this->assertTrue(file_unmanaged_copy("{$src_dir}/{$field_config_name_2b}.yml", "{$target_dir}/{$field_config_name_2b}.yml"));
// Import the content of the sync directory.
$this->configImporter()->import();
// Check that the field and storage were created.
$field_storage = FieldStorageConfig::load($field_storage_id);
$this->assertTrue($field_storage, 'Test import storage field from sync exists');
$field = FieldConfig::load($field_id);
$this->assertTrue($field, 'Test import field from sync exists');
$field_storage = FieldStorageConfig::load($field_storage_id_2);
$this->assertTrue($field_storage, 'Test import storage field 2 from sync exists');
$field = FieldConfig::load($field_id_2a);
$this->assertTrue($field, 'Test import field 2a from sync exists');
$field = FieldConfig::load($field_id_2b);
$this->assertTrue($field, 'Test import field 2b from sync exists');
}
示例10: execute
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$messageHelper = $this->getMessageHelper();
$directory = $input->getOption('directory');
$tar = $input->getOption('tar');
$archiveTar = new ArchiveTar();
if (!$directory) {
$directory = config_get_config_directory(CONFIG_SYNC_DIRECTORY);
}
if ($tar) {
if (!is_dir($directory)) {
mkdir($directory, 0777, true);
}
$dateTime = new \DateTime();
$archiveFile = sprintf('%s/config-%s.tar.gz', $directory, $dateTime->format('Y-m-d-H-i-s'));
$archiveTar = new ArchiveTar($archiveFile, 'gz');
}
try {
$configManager = $this->getConfigManager();
// Get raw configuration data without overrides.
foreach ($configManager->getConfigFactory()->listAll() as $name) {
$configData = $configManager->getConfigFactory()->get($name)->getRawData();
$configName = sprintf('%s.yml', $name);
$ymlData = Yaml::encode($configData);
if ($tar) {
$archiveTar->addString($configName, $ymlData);
continue;
}
$configFileName = sprintf('%s/%s', $directory, $configName);
file_put_contents($configFileName, $ymlData);
}
} catch (\Exception $e) {
$output->writeln('[+] <error>' . $e->getMessage() . '</error>');
return;
}
$messageHelper->addSuccessMessage(sprintf($this->trans('commands.config.export.messages.directory')));
$messageHelper->addSuccessMessage($directory);
}
示例11: execute
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new DrupalStyle($input, $output);
$archiveFile = $input->getOption('file');
$directory = $input->getOption('directory');
$removeFiles = $input->getOption('remove-files');
if ($directory) {
$configSyncDir = $directory;
} else {
$configSyncDir = config_get_config_directory(CONFIG_SYNC_DIRECTORY);
}
// Determine $source_storage in partial and non-partial cases.
$active_storage = \Drupal::service('config.storage');
$source_storage = new FileStorage($configSyncDir);
/** @var \Drupal\Core\Config\ConfigManagerInterface $config_manager */
$config_manager = \Drupal::service('config.manager');
$storage_comparer = new StorageComparer($source_storage, $active_storage, $config_manager);
if (!$storage_comparer->createChangelist()->hasChanges()) {
$io->success($this->trans('commands.config.import.messages.nothing-to-do'));
}
if ($this->configImport($io, $storage_comparer)) {
$io->success($this->trans('commands.config.import.messages.imported'));
}
}
示例12: execute
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new DrupalStyle($input, $output);
$directory = $input->getOption('directory');
$module = $input->getOption('module');
$configName = $input->getArgument('config-name');
$optionalConfig = $input->getOption('optional-config');
$config = $this->getConfiguration($configName);
if ($config) {
if (!$directory) {
$directory = config_get_config_directory(CONFIG_SYNC_DIRECTORY);
}
$this->configExport[$configName] = array('data' => $config, 'optional' => $optionalConfig);
if ($input->getOption('include-dependencies')) {
// Include config dependencies in export files
if ($dependencies = $this->fetchDependencies($config, 'config')) {
$this->resolveDependencies($dependencies, $optionalConfig);
}
}
} else {
$io->error($this->trans('commands.config.export.single.messages.config-not-found'));
}
if (!$module) {
if (!$directory) {
$directory = config_get_config_directory(CONFIG_SYNC_DIRECTORY);
}
$this->exportConfig($directory, $io, $this->trans('commands.config.export.single.messages.config_exported'));
} else {
$this->exportConfigToModule($module, $io, $this->trans('commands.config.export.single.messages.config_exported'));
}
}
示例13: prepareEnvironment
/**
* Prepares the current environment for running the test.
*
* Backups various current environment variables and resets them, so they do
* not interfere with the Backdrop site installation in which tests are executed
* and can be restored in tearDown().
*
* Also sets up new resources for the testing environment, such as the public
* filesystem and configuration directories.
*
* @see BackdropWebTestCase::setUp()
* @see BackdropWebTestCase::tearDown()
*/
protected function prepareEnvironment()
{
global $user, $language, $settings, $config_directories;
// Store necessary current values before switching to prefixed database.
$this->originalLanguage = $language;
$this->originalLanguageDefault = config_get('system.core', 'language_default');
$this->originalConfigDirectories = $config_directories;
$this->originalFileDirectory = config_get('system.core', 'file_public_path', 'files');
$this->originalProfile = backdrop_get_profile();
$this->originalCleanUrl = config_get('system.core', 'clean_url');
$this->originalUser = $user;
$this->originalSettings = $settings;
// Set to English to prevent exceptions from utf8_truncate() from t()
// during install if the current language is not 'en'.
// The following array/object conversion is copied from language_default().
$language = (object) array('langcode' => 'en', 'name' => 'English', 'direction' => 0, 'enabled' => 1, 'weight' => 0);
// Save and clean the shutdown callbacks array because it is static cached
// and will be changed by the test run. Otherwise it will contain callbacks
// from both environments and the testing environment will try to call the
// handlers defined by the original one.
$callbacks =& backdrop_register_shutdown_function();
$this->originalShutdownCallbacks = $callbacks;
$callbacks = array();
// Create test directory ahead of installation so fatal errors and debug
// information can be logged during installation process.
// Use temporary files directory with the same prefix as the database.
$this->public_files_directory = $this->originalFileDirectory . '/simpletest/' . substr($this->databasePrefix, 10);
$this->private_files_directory = $this->public_files_directory . '/private';
$this->temp_files_directory = $this->private_files_directory . '/temp';
// Create the directories.
file_prepare_directory($this->public_files_directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS);
file_prepare_directory($this->private_files_directory, FILE_CREATE_DIRECTORY);
file_prepare_directory($this->temp_files_directory, FILE_CREATE_DIRECTORY);
$this->generatedTestFiles = FALSE;
// Set the new config directories. During test execution, these values are
// manually set directly in config_get_config_directory().
$config_base_path = 'files/simpletest/' . substr($this->databasePrefix, 10) . '/config_';
$config_directories['active'] = $config_base_path . 'active';
$config_directories['staging'] = $config_base_path . 'staging';
$active_directory = config_get_config_directory('active');
$staging_directory = config_get_config_directory('staging');
file_prepare_directory($active_directory, FILE_CREATE_DIRECTORY);
file_prepare_directory($staging_directory, FILE_CREATE_DIRECTORY);
// Log fatal errors.
ini_set('log_errors', 1);
ini_set('error_log', $this->public_files_directory . '/error.log');
// Set the test information for use in other parts of Backdrop.
$test_info =& $GLOBALS['backdrop_test_info'];
$test_info['test_run_id'] = $this->databasePrefix;
$test_info['in_child_site'] = FALSE;
// Disable Drupal compatibility for test runs.
$settings['backdrop_drupal_compatibility'] = FALSE;
// Indicate the environment was set up correctly.
$this->setupEnvironment = TRUE;
}
示例14: testConfigGetConfigDirectory
/**
* Tests config_get_config_directory().
*/
public function testConfigGetConfigDirectory()
{
$directory = config_get_config_directory(CONFIG_SYNC_DIRECTORY);
$this->assertEqual($this->configDirectories[CONFIG_SYNC_DIRECTORY], $directory);
$message = 'Calling config_get_config_directory() with CONFIG_ACTIVE_DIRECTORY results in an exception.';
try {
config_get_config_directory(CONFIG_ACTIVE_DIRECTORY);
$this->fail($message);
} catch (\Exception $e) {
$this->pass($message);
}
}
示例15: getConfigurationData
protected function getConfigurationData()
{
try {
$active = config_get_config_directory('active');
$staging = config_get_config_directory('staging');
} catch (\Exception $e) {
$active = '';
$staging = '';
}
return ['configuration' => [$this->trans('commands.site.status.messages.active') => $active, $this->trans('commands.site.status.messages.staging') => $staging]];
}