本文整理汇总了PHP中Drupal::hasContainer方法的典型用法代码示例。如果您正苦于以下问题:PHP Drupal::hasContainer方法的具体用法?PHP Drupal::hasContainer怎么用?PHP Drupal::hasContainer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal
的用法示例。
在下文中一共展示了Drupal::hasContainer方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __wakeup
/**
* {@inheritdoc}
*/
public function __wakeup()
{
// Tests in isolation potentially unserialize in the parent process.
if (isset($GLOBALS['__PHPUNIT_BOOTSTRAP']) && !\Drupal::hasContainer()) {
return;
}
$container = \Drupal::getContainer();
foreach ($this->_serviceIds as $key => $service_id) {
$this->{$key} = $container->get($service_id);
}
$this->_serviceIds = array();
}
示例2: testDrupalGetFilename
/**
* Tests that drupal_get_filename() works when the file is not in database.
*/
function testDrupalGetFilename()
{
// drupal_get_profile() is using obtaining the profile from state if the
// install_state global is not set.
global $install_state;
$install_state['parameters']['profile'] = 'testing';
// Assert that this test is meaningful.
$this->assertNull($this->container);
$this->assertFalse(\Drupal::hasContainer());
// Retrieving the location of a module.
$this->assertIdentical(drupal_get_filename('module', 'system'), 'core/modules/system/system.info.yml');
// Retrieving the location of a theme.
$this->assertIdentical(drupal_get_filename('theme', 'stark'), 'core/themes/stark/stark.info.yml');
// Retrieving the location of a theme engine.
$this->assertIdentical(drupal_get_filename('theme_engine', 'phptemplate'), 'core/themes/engines/phptemplate/phptemplate.info.yml');
// Retrieving the location of a profile. Profiles are a special case with
// a fixed location and naming.
$this->assertIdentical(drupal_get_filename('profile', 'standard'), 'core/profiles/standard/standard.info.yml');
// Searching for an item that does not exist returns NULL.
$this->assertNull(drupal_get_filename('module', uniqid("", TRUE)), 'Searching for an item that does not exist returns NULL.');
}
示例3: unserialize
/**
* {@inheritdoc}
*/
public function unserialize($serialized)
{
list($storage, $current_display, $args, $current_page, $exposed_input, $exposed_raw_input, $exposed_data, $dom_id, $executed) = unserialize($serialized);
// There are cases, like in testing, where we don't have a container
// available.
if (\Drupal::hasContainer()) {
$this->setRequest(\Drupal::request());
$this->user = \Drupal::currentUser();
$this->storage = \Drupal::entityManager()->getStorage('view')->load($storage);
$this->setDisplay($current_display);
$this->setArguments($args);
$this->setCurrentPage($current_page);
$this->setExposedInput($exposed_input);
$this->exposed_data = $exposed_data;
$this->exposed_raw_input = $exposed_raw_input;
$this->dom_id = $dom_id;
$this->initHandlers();
// If the display was previously executed, execute it now.
if ($executed) {
$this->execute($this->current_display);
}
}
}
示例4: setupEntityTypeManager
/**
* Sets up the entity type manager in the container.
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
*/
protected function setupEntityTypeManager(EntityTypeManagerInterface $entity_type_manager)
{
$container = \Drupal::hasContainer() ? \Drupal::getContainer() : new ContainerBuilder();
$container->set('entity_type.manager', $entity_type_manager);
$container->set('entity.manager', $entity_type_manager);
\Drupal::setContainer($container);
}
示例5: setupNullCacheabilityMetadataValidation
protected function setupNullCacheabilityMetadataValidation() {
$container = \Drupal::hasContainer() ? \Drupal::getContainer() : new ContainerBuilder();
$cache_context_manager = $this->prophesize(CacheContextsManager::class);
$container->set('cache_contexts_manager', $cache_context_manager->reveal());
\Drupal::setContainer($container);
}
示例6: setupNullCacheabilityMetadataValidation
protected function setupNullCacheabilityMetadataValidation()
{
$container = \Drupal::hasContainer() ? \Drupal::getContainer() : new ContainerBuilder();
$cache_context_manager = $this->prophesize(CacheContextsManager::class);
foreach ([NULL, ['user.permissions'], ['route'], ['route', 'context.example1'], ['context.example1', 'route'], ['context.example1', 'route', 'context.example2'], ['context.example1', 'context.example2', 'route'], ['context.example1', 'context.example2', 'route', 'user.permissions']] as $argument) {
$cache_context_manager->assertValidTokens($argument)->willReturn(TRUE);
}
$container->set('cache_contexts_manager', $cache_context_manager->reveal());
\Drupal::setContainer($container);
}