예제 #1
0
 /**
  * Gets the PHP code storage object to use for the compiled Twig files.
  *
  * @return \Drupal\Component\PhpStorage\PhpStorageInterface
  */
 protected function storage()
 {
     if (!isset($this->storage)) {
         $this->storage = PhpStorageFactory::get('twig');
     }
     return $this->storage;
 }
 /**
  * Tests the get() method with overridden settings.
  */
 public function testGetOverride()
 {
     $this->setSettings('test');
     $php = PhpStorageFactory::get('test');
     // The FileReadOnlyStorage should be used from settings.
     $this->assertTrue($php instanceof MockPhpStorage, 'A MockPhpStorage instance was returned from overridden settings.');
     // Test that the name is used for the bin when it is NULL.
     $this->setSettings('test', array('bin' => NULL));
     $php = PhpStorageFactory::get('test');
     $this->assertTrue($php instanceof MockPhpStorage, 'An MockPhpStorage instance was returned from overridden settings.');
     $this->assertSame('test', $php->getConfigurationValue('bin'), 'Name value was used for bin.');
     // Test that a default directory is set if it's empty.
     $this->setSettings('test', array('directory' => NULL));
     $php = PhpStorageFactory::get('test');
     $this->assertTrue($php instanceof MockPhpStorage, 'An MockPhpStorage instance was returned from overridden settings.');
     $this->assertSame(PublicStream::basePath() . '/php', $php->getConfigurationValue('directory'), 'Default file directory was used.');
     // Test that a default storage class is set if it's empty.
     $this->setSettings('test', array('class' => NULL));
     $php = PhpStorageFactory::get('test');
     $this->assertTrue($php instanceof MTimeProtectedFileStorage, 'An MTimeProtectedFileStorage instance was returned from overridden settings with no class.');
     // Test that a default secret is not returned if it's set in the override.
     $this->setSettings('test');
     $php = PhpStorageFactory::get('test');
     $this->assertNotEquals('mock hash salt', $php->getConfigurationValue('secret'), 'The default secret is not used if a secret is set in the overridden settings.');
     // Test that a default secret is set if it's empty.
     $this->setSettings('test', array('secret' => NULL));
     $php = PhpStorageFactory::get('test');
     $this->assertSame('mock hash salt', $php->getConfigurationValue('secret'), 'The default secret is used if one is not set in the overridden settings.');
 }
예제 #3
0
 /**
  * Ensures Twig template cache setting can be overridden.
  */
 function testTwigCacheOverride()
 {
     $extension = twig_extension();
     $theme_handler = $this->container->get('theme_handler');
     $theme_handler->enable(array('test_theme'));
     $theme_handler->setDefault('test_theme');
     // The registry still works on theme globals, so set them here.
     $GLOBALS['theme'] = 'test_theme';
     $GLOBALS['theme_info'] = $theme_handler->listInfo()['test_theme'];
     // Reset the theme registry, so that the new theme is used.
     $this->container->set('theme.registry', NULL);
     // Load array of Twig templates.
     // reset() is necessary to invalidate caches tagged with 'theme_registry'.
     $registry = $this->container->get('theme.registry');
     $registry->reset();
     $templates = $registry->getRuntime();
     // Get the template filename and the cache filename for
     // theme_test.template_test.html.twig.
     $info = $templates->get('theme_test_template_test');
     $template_filename = $info['path'] . '/' . $info['template'] . $extension;
     $cache_filename = $this->container->get('twig')->getCacheFilename($template_filename);
     // Navigate to the page and make sure the template gets cached.
     $this->drupalGet('theme-test/template-test');
     $this->assertTrue(PhpStorageFactory::get('twig')->exists($cache_filename), 'Cached Twig template found.');
     // Disable the Twig cache and rebuild the service container.
     $this->settingsSet('twig_cache', FALSE);
     $this->rebuildContainer();
     // This should return false after rebuilding the service container.
     $new_cache_filename = $this->container->get('twig')->getCacheFilename($template_filename);
     $this->assertFalse($new_cache_filename, 'Twig environment does not return cache filename after caching is disabled.');
 }
예제 #4
0
 /**
  * Causes the container to be rebuilt on the next request.
  *
  * @param ConfigCrudEvent $event
  *   The configuration event.
  */
 public function onConfigSave(ConfigCrudEvent $event)
 {
     $saved_config = $event->getConfig();
     if ($saved_config->getName() == 'system.site' && $event->isChanged('langcode')) {
         // Trigger a container rebuild on the next request by deleting compiled
         // from PHP storage.
         PhpStorageFactory::get('service_container')->deleteAll();
     }
 }
예제 #5
0
 /**
  * Constructs a SplitFieldsDiffLayout object.
  *
  * @param array $configuration
  *   A configuration array containing information about the plugin instance.
  * @param string $plugin_id
  *   The plugin_id for the plugin instance.
  * @param mixed $plugin_definition
  *   The plugin implementation definition.
  * @param \Drupal\Core\Config\ConfigFactoryInterface $config
  *   The configuration factory object.
  * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
  *   The entity type manager.
  * @param \Drupal\diff\DiffEntityParser $entity_parser
  *   The entity parser.
  * @param \Drupal\Core\DateTime\DateFormatter $date
  *   The date service.
  * @param \Drupal\Core\Render\RendererInterface $renderer
  *   The renderer.
  * @param \Drupal\diff\DiffEntityComparison $entity_comparison
  *   The diff entity comparison service.
  * @param \Symfony\Component\HttpFoundation\RequestStack $request_stack
  *   The request stack.
  */
 public function __construct(array $configuration, $plugin_id, $plugin_definition, ConfigFactoryInterface $config, EntityTypeManagerInterface $entity_type_manager, DiffEntityParser $entity_parser, DateFormatter $date, RendererInterface $renderer, DiffEntityComparison $entity_comparison, RequestStack $request_stack, HtmlDiffAdvancedInterface $html_diff)
 {
     parent::__construct($configuration, $plugin_id, $plugin_definition, $config, $entity_type_manager, $entity_parser, $date);
     $this->renderer = $renderer;
     $this->entityComparison = $entity_comparison;
     $this->requestStack = $request_stack;
     $storage = PhpStorageFactory::get('html_purifier_serializer');
     if (!$storage->exists('cache.php')) {
         $storage->save('cache.php', 'dummy');
     }
     $html_diff->getConfig()->setPurifierCacheLocation(dirname($storage->getFullPath('cache.php')));
     $this->htmlDiff = $html_diff;
 }
 /**
  * Causes the container to be rebuilt on the next request.
  *
  * @param ConfigCrudEvent $event
  *   The configuration event.
  */
 public function onConfigSave(ConfigCrudEvent $event)
 {
     $saved_config = $event->getConfig();
     if ($saved_config->getName() == 'system.site' && $event->isChanged('langcode')) {
         $language = $this->languageManager->getLanguage($saved_config->get('langcode'));
         // During an import the language might not exist yet.
         if ($language) {
             $this->languageDefault->set($language);
             $this->languageManager->reset();
             language_negotiation_url_prefixes_update();
         }
         // Trigger a container rebuild on the next request by deleting compiled
         // from PHP storage.
         PhpStorageFactory::get('service_container')->deleteAll();
     }
 }
예제 #7
0
 /**
  * Submodules constructor.
  * @param string|null $module
  * @param bool $reset
  */
 function __construct($module = NULL, $reset = FALSE)
 {
     if (static::$module || !$module) {
         return;
     }
     static::$module = $module;
     $storage = PhpStorageFactory::get($module);
     if ($reset || $this->isReset() || !$storage->exists($module)) {
         $this->scanImplementations();
         $this->sortImplementations();
         $this->generateCode();
         $storage->deleteAll();
         $storage->save($module, implode("\n\n", $this->code) . "\n");
         Drupal::configFactory()->getEditable(static::$module . '.settings')->delete();
     }
     require_once $storage->getFullPath($module);
 }
예제 #8
0
 /**
  * Gets the PHP code storage object to use for the compiled container.
  *
  * @return \Drupal\Component\PhpStorage\PhpStorageInterface
  */
 protected function storage()
 {
     if (!isset($this->storage)) {
         $this->storage = PhpStorageFactory::get('service_container');
     }
     return $this->storage;
 }
예제 #9
0
 /**
  * Ensures Twig template cache setting can be overridden.
  */
 function testTwigCacheOverride()
 {
     $extension = twig_extension();
     $theme_handler = $this->container->get('theme_handler');
     $theme_handler->install(array('test_theme'));
     $theme_handler->setDefault('test_theme');
     // The registry still works on theme globals, so set them here.
     \Drupal::theme()->setActiveTheme(\Drupal::service('theme.initialization')->getActiveThemeByName('test_theme'));
     // Reset the theme registry, so that the new theme is used.
     $this->container->set('theme.registry', NULL);
     // Load array of Twig templates.
     // reset() is necessary to invalidate caches tagged with 'theme_registry'.
     $registry = $this->container->get('theme.registry');
     $registry->reset();
     $templates = $registry->getRuntime();
     // Get the template filename and the cache filename for
     // theme_test.template_test.html.twig.
     $info = $templates->get('theme_test_template_test');
     $template_filename = $info['path'] . '/' . $info['template'] . $extension;
     $cache_filename = $this->container->get('twig')->getCacheFilename($template_filename);
     // Navigate to the page and make sure the template gets cached.
     $this->drupalGet('theme-test/template-test');
     $this->assertTrue(PhpStorageFactory::get('twig')->exists($cache_filename), 'Cached Twig template found.');
     // Disable the Twig cache and rebuild the service container.
     $parameters = $this->container->getParameter('twig.config');
     $parameters['cache'] = FALSE;
     $this->setContainerParameter('twig.config', $parameters);
     $this->rebuildContainer();
     // This should return false after rebuilding the service container.
     $this->assertFalse($this->container->get('twig')->getCache(), 'Twig environment has caching disabled.');
 }
 /**
  * {@inheritdoc}
  */
 public static function rebuildServices()
 {
     PhpStorageFactory::get('service_container')->deleteAll();
 }
예제 #11
0
 /**
  * @Todo: Remove when issue https://www.drupal.org/node/2556025 get resolved
  *
  * Rebuilds all caches even when Drupal itself does not work.
  *
  * @param \Composer\Autoload\ClassLoader $class_loader
  *   The class loader.
  * @param \Symfony\Component\HttpFoundation\Request $request
  *   The current request.
  *
  * @see rebuild.php
  */
 public function drupal_rebuild($class_loader, \Symfony\Component\HttpFoundation\Request $request)
 {
     // Remove Drupal's error and exception handlers; they rely on a working
     // service container and other subsystems and will only cause a fatal error
     // that hides the actual error.
     restore_error_handler();
     restore_exception_handler();
     // Force kernel to rebuild php cache.
     \Drupal\Core\PhpStorage\PhpStorageFactory::get('twig')->deleteAll();
     // Bootstrap up to where caches exist and clear them.
     $kernel = new \Drupal\Core\DrupalKernel('prod', $class_loader);
     $kernel->setSitePath(\Drupal\Core\DrupalKernel::findSitePath($request));
     // Invalidate the container.
     $kernel->invalidateContainer();
     // Prepare a NULL request.
     $kernel->prepareLegacyRequest($request);
     foreach (Cache::getBins() as $bin) {
         $bin->deleteAll();
     }
     // Disable recording of cached pages.
     \Drupal::service('page_cache_kill_switch')->trigger();
     drupal_flush_all_caches();
     // Restore Drupal's error and exception handlers.
     // @see \Drupal\Core\DrupalKernel::boot()
     set_error_handler('_drupal_error_handler');
     set_exception_handler('_drupal_exception_handler');
 }