当前位置: 首页>>代码示例>>PHP>>正文


PHP Drupal::lock方法代码示例

本文整理汇总了PHP中Drupal::lock方法的典型用法代码示例。如果您正苦于以下问题:PHP Drupal::lock方法的具体用法?PHP Drupal::lock怎么用?PHP Drupal::lock使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Drupal的用法示例。


在下文中一共展示了Drupal::lock方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: configImport

 private function configImport($io, StorageComparer $storage_comparer)
 {
     $config_importer = new ConfigImporter($storage_comparer, \Drupal::service('event_dispatcher'), \Drupal::service('config.manager'), \Drupal::lock(), \Drupal::service('config.typed'), \Drupal::moduleHandler(), \Drupal::service('module_installer'), \Drupal::service('theme_handler'), \Drupal::service('string_translation'));
     if ($config_importer->alreadyImporting()) {
         $io->success($this->trans('commands.config.import.messages.already-imported'));
     } else {
         try {
             if ($config_importer->validate()) {
                 $sync_steps = $config_importer->initialize();
                 foreach ($sync_steps as $step) {
                     $context = array();
                     do {
                         $config_importer->doSyncStep($step, $context);
                     } while ($context['finished'] < 1);
                 }
             }
         } catch (ConfigImporterException $e) {
             $message = 'The import failed due for the following reasons:' . "\n";
             $message .= implode("\n", $config_importer->getErrors());
             $io->error(sprintf($this->trans('commands.site.import.local.messages.error-writing'), $message));
         } catch (\Exception $e) {
             $io->error(sprintf($this->trans('commands.site.import.local.messages.error-writing'), $e->getMessage()));
         }
     }
 }
开发者ID:jeyram,项目名称:DrupalConsole,代码行数:25,代码来源:ImportSingleCommand.php

示例2: testRaceCondition

 /**
  * Tests the behavior of the theme registry class.
  */
 function testRaceCondition()
 {
     // The theme registry is not marked as persistable in case we don't have a
     // proper request.
     \Drupal::request()->setMethod('GET');
     $cid = 'test_theme_registry';
     // Directly instantiate the theme registry, this will cause a base cache
     // entry to be written in __construct().
     $cache = \Drupal::cache();
     $lock_backend = \Drupal::lock();
     $registry = new ThemeRegistry($cid, $cache, $lock_backend, array('theme_registry'), $this->container->get('module_handler')->isLoaded());
     $this->assertTrue(\Drupal::cache()->get($cid), 'Cache entry was created.');
     // Trigger a cache miss for an offset.
     $this->assertTrue($registry->get('theme_test_template_test'), 'Offset was returned correctly from the theme registry.');
     // This will cause the ThemeRegistry class to write an updated version of
     // the cache entry when it is destroyed, usually at the end of the request.
     // Before that happens, manually delete the cache entry we created earlier
     // so that the new entry is written from scratch.
     \Drupal::cache()->delete($cid);
     // Destroy the class so that it triggers a cache write for the offset.
     $registry->destruct();
     $this->assertTrue(\Drupal::cache()->get($cid), 'Cache entry was created.');
     // Create a new instance of the class. Confirm that both the offset
     // requested previously, and one that has not yet been requested are both
     // available.
     $registry = new ThemeRegistry($cid, $cache, $lock_backend, array('theme_registry'), $this->container->get('module_handler')->isLoaded());
     $this->assertTrue($registry->get('theme_test_template_test'), 'Offset was returned correctly from the theme registry');
     $this->assertTrue($registry->get('theme_test_template_test_2'), 'Offset was returned correctly from the theme registry');
 }
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:32,代码来源:RegistryTest.php

示例3: testStableTemplateOverrides

 /**
  * Ensures that Stable overrides all relevant core templates.
  */
 public function testStableTemplateOverrides()
 {
     $registry = new Registry(\Drupal::root(), \Drupal::cache(), \Drupal::lock(), \Drupal::moduleHandler(), $this->themeHandler, \Drupal::service('theme.initialization'), 'stable');
     $registry->setThemeManager(\Drupal::theme());
     $registry_full = $registry->get();
     foreach ($registry_full as $hook => $info) {
         if (isset($info['template'])) {
             // Allow skipping templates.
             if (in_array($info['template'], $this->templatesToSkip)) {
                 continue;
             }
             $this->assertEquals('core/themes/stable', $info['theme path'], $info['template'] . '.html.twig overridden in Stable.');
         }
     }
 }
开发者ID:sojo,项目名称:d8_friendsofsilence,代码行数:18,代码来源:StableTemplateOverrideTest.php

示例4: configImport

 private function configImport(DrupalStyle $io, StorageComparer $storage_comparer)
 {
     $config_importer = new ConfigImporter($storage_comparer, \Drupal::service('event_dispatcher'), \Drupal::service('config.manager'), \Drupal::lock(), \Drupal::service('config.typed'), \Drupal::moduleHandler(), \Drupal::service('module_installer'), \Drupal::service('theme_handler'), \Drupal::service('string_translation'));
     if ($config_importer->alreadyImporting()) {
         $io->success($this->trans('commands.config.import.messages.already-imported'));
     } else {
         try {
             $config_importer->import();
             $io->info($this->trans('commands.config.import.messages.importing'));
         } catch (ConfigImporterException $e) {
             $message = 'The import failed due for the following reasons:' . "\n";
             $message .= implode("\n", $config_importer->getErrors());
             $io->error(sprintf($this->trans('commands.site.import.local.messages.error-writing'), $message));
         } catch (\Exception $e) {
             $io->error(sprintf($this->trans('commands.site.import.local.messages.error-writing'), $e->getMessage()));
         }
     }
 }
开发者ID:jeyram,项目名称:DrupalConsole,代码行数:18,代码来源:ImportCommand.php

示例5: releaseThreadLock

 /**
  * Release the lock acquired for the thread in preSave().
  */
 protected function releaseThreadLock()
 {
     if ($this->threadLock) {
         \Drupal::lock()->release($this->threadLock);
         $this->threadLock = '';
     }
 }
开发者ID:brstde,项目名称:gap1,代码行数:10,代码来源:Comment.php

示例6: testThemeRegistryAlterByTheme

 /**
  * Tests that the theme registry can be altered by themes.
  */
 public function testThemeRegistryAlterByTheme()
 {
     /** @var \Drupal\Core\Extension\ThemeHandlerInterface $theme_handler */
     $theme_handler = \Drupal::service('theme_handler');
     $theme_handler->install(['test_theme']);
     $theme_handler->setDefault('test_theme');
     $registry = new Registry(\Drupal::root(), \Drupal::cache(), \Drupal::lock(), \Drupal::moduleHandler(), $theme_handler, \Drupal::service('theme.initialization'), 'test_theme');
     $registry->setThemeManager(\Drupal::theme());
     $this->assertEqual('value', $registry->get()['theme_test_template_test']['variables']['additional']);
 }
开发者ID:Nikola-xiii,项目名称:d8intranet,代码行数:13,代码来源:RegistryTest.php

示例7: getNextCid

 /**
  * @param $config
  *
  * @return mixed
  */
 protected function getNextCid()
 {
     $config = $this->getConfiguration();
     $nid = $config['nid'];
     $lock = \Drupal::lock();
     if ($lock->acquire('webform_component_insert_' . $nid, 5)) {
         $next_id_query = db_select('webform_component')->condition('nid', $nid);
         $next_id_query->addExpression('MAX(cid) + 1', 'cid');
         $cid = $next_id_query->execute()->fetchField();
         if ($cid == NULL) {
             $cid = 1;
         }
         $lock->release('webform_component_insert_' . $nid);
         return $cid;
     } else {
         \Drupal::logger('webform')->critical('A Webform component could not be saved because a timeout occurred while trying to acquire a lock for the node. Details: <pre>@component</pre>', array('@component' => print_r($config, TRUE)));
         return NULL;
     }
 }
开发者ID:Progressable,项目名称:openway8,代码行数:24,代码来源:ComponentBase.php

示例8: testLock

 /**
  * Tests the lock() method.
  *
  * @covers ::lock
  */
 public function testLock()
 {
     $this->setMockContainerService('lock');
     $this->assertNotNull(\Drupal::lock());
 }
开发者ID:dmyerson,项目名称:d8ecs,代码行数:10,代码来源:DrupalTest.php

示例9: reInjectMe

 /**
  * Gets all the service dependencies from \Drupal.
  *
  * Since the ConfigImporter handles module installation the kernel and the
  * container can be rebuilt and altered during processing. It is necessary to
  * keep the services used by the importer in sync.
  */
 protected function reInjectMe()
 {
     $this->eventDispatcher = \Drupal::service('event_dispatcher');
     $this->configManager = \Drupal::service('config.manager');
     $this->lock = \Drupal::lock();
     $this->typedConfigManager = \Drupal::service('config.typed');
     $this->moduleHandler = \Drupal::moduleHandler();
     $this->themeHandler = \Drupal::service('theme_handler');
     $this->stringTranslation = \Drupal::service('string_translation');
 }
开发者ID:anatalsceo,项目名称:en-classe,代码行数:17,代码来源:ConfigImporter.php

示例10: releaseLock

 /**
  * Releases a lock for this source.
  *
  * @return self
  *   Returns the Feed for method chaining.
  */
 protected function releaseLock()
 {
     \Drupal::lock()->release("feeds_feed_{$this->id()}");
     return $this;
 }
开发者ID:alnutile,项目名称:drunatra,代码行数:11,代码来源:Feed.php


注:本文中的Drupal::lock方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。