utility.inc 1.8 KB
Newer Older
1 2 3 4 5 6 7
<?php

/**
 * @file
 * Miscellaneous functions.
 */

8
use Drupal\Component\Utility\Variable;
9
use Drupal\Core\PhpStorage\PhpStorageFactory;
10
use Drupal\Core\Cache\Cache;
11

12 13 14
/**
 * Drupal-friendly var_export().
 *
15
 * @param mixed $var
16
 *   The variable to export.
17
 * @param string $prefix
18
 *   A prefix that will be added at the beginning of every lines of the output.
19
 *
20
 * @return string
21
 *   The variable exported in a way compatible to Drupal's coding standards.
22
 *
23 24
 * @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0.
 *   Use \Drupal\Component\Utility\Variable::export().
25 26
 */
function drupal_var_export($var, $prefix = '') {
27
  return Variable::export($var, $prefix);
28
}
29 30 31 32 33 34 35 36

/**
 * Rebuilds all caches even when Drupal itself does not work.
 *
 * Requires DRUPAL_BOOTSTRAP_CONFIGURATION.
 *
 * @see rebuild.php
 */
37
function drupal_rebuild() {
38 39 40 41 42 43
  // 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();

44 45
  // drupal_bootstrap(DRUPAL_BOOTSTRAP_KERNEL) will build a new kernel. This
  // comes before DRUPAL_BOOTSTRAP_PAGE_CACHE.
46 47 48
  PhpStorageFactory::get('service_container')->deleteAll();
  PhpStorageFactory::get('twig')->deleteAll();

49 50
  // Disable the page cache.
  drupal_page_is_cacheable(FALSE);
51

52 53
  // Bootstrap up to where caches exist and clear them.
  drupal_bootstrap(DRUPAL_BOOTSTRAP_PAGE_CACHE);
54 55 56 57
  foreach (Cache::getBins() as $bin) {
    $bin->deleteAll();
  }

58
  drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
59
  drupal_flush_all_caches();
60 61

  // Restore Drupal's error and exception handlers.
62
  // @see _drupal_bootstrap_configuration()
63 64
  set_error_handler('_drupal_error_handler');
  set_exception_handler('_drupal_exception_handler');
65
}