/** * Constructs an ApcuBackendFactory object. * * @param string $root * The app root. * @param string $site_path * The site path. * @param \Drupal\Core\Cache\CacheTagsChecksumInterface $checksum_provider * The cache tags checksum provider. */ public function __construct($root, $site_path, CacheTagsChecksumInterface $checksum_provider) { $this->sitePrefix = Settings::getApcuPrefix('apcu_backend', $root, $site_path); $this->checksumProvider = $checksum_provider; if (version_compare(phpversion('apcu'), '5.0.0', '>=')) { $this->backendClass = 'Drupal\\Core\\Cache\\ApcuBackend'; } else { $this->backendClass = 'Drupal\\Core\\Cache\\Apcu4Backend'; } }
/** * {@inheritdoc} */ public function setUp() { // @todo Extra hack to avoid test fails, remove this once // https://www.drupal.org/node/2553661 is fixed. FileCacheFactory::setPrefix(Settings::getApcuPrefix('file_cache', $this->root)); parent::setUp(); $this->logger = $this->container->get('logger.channel.rules'); // Clear the log from any stale entries that are bleeding over from previous // tests. $this->logger->clearLogs(); $this->expressionManager = $this->container->get('plugin.manager.rules_expression'); $this->conditionManager = $this->container->get('plugin.manager.condition'); $this->typedDataManager = $this->container->get('typed_data_manager'); }
/** * Constructs an ApcuBackendFactory object. * * @param string $root * The app root. * @param string $site_path * The site path. * @param \Drupal\Core\Cache\CacheTagsChecksumInterface $checksum_provider * The cache tags checksum provider. */ public function __construct($root, $site_path, CacheTagsChecksumInterface $checksum_provider) { $this->sitePrefix = Settings::getApcuPrefix('apcu_backend', $root, $site_path); $this->checksumProvider = $checksum_provider; }
/** * Locate site path and initialize settings singleton. * * @param \Symfony\Component\HttpFoundation\Request $request * The current request. * * @throws \Symfony\Component\HttpKernel\Exception\BadRequestHttpException * In case the host name in the request is not trusted. */ protected function initializeSettings(Request $request) { $site_path = static::findSitePath($request); $this->setSitePath($site_path); $class_loader_class = get_class($this->classLoader); Settings::initialize($this->root, $site_path, $this->classLoader); // Initialize our list of trusted HTTP Host headers to protect against // header attacks. $host_patterns = Settings::get('trusted_host_patterns', array()); if (PHP_SAPI !== 'cli' && !empty($host_patterns)) { if (static::setupTrustedHosts($request, $host_patterns) === FALSE) { throw new BadRequestHttpException('The provided host name is not valid for this server.'); } } // If the class loader is still the same, possibly upgrade to the APC class // loader. if ($class_loader_class == get_class($this->classLoader) && Settings::get('class_loader_auto_detect', TRUE) && function_exists('apcu_fetch')) { $prefix = Settings::getApcuPrefix('class_loader', $this->root); $apc_loader = new ApcClassLoader($prefix, $this->classLoader); $this->classLoader->unregister(); $apc_loader->register(); $this->classLoader = $apc_loader; } }
/** * Initializes the FileCache component. * * We can not use the Settings object in a component, that's why we have to do * it here instead of \Drupal\Component\FileCache\FileCacheFactory. */ protected function initFileCache() { $configuration = Settings::get('file_cache'); // Provide a default configuration, if not set. if (!isset($configuration['default'])) { $configuration['default'] = ['class' => FileCache::class, 'cache_backend_class' => NULL, 'cache_backend_configuration' => []]; // @todo Use extension_loaded('apcu') for non-testbot // https://www.drupal.org/node/2447753. if (function_exists('apcu_fetch')) { $configuration['default']['cache_backend_class'] = ApcuFileCacheBackend::class; } } FileCacheFactory::setConfiguration($configuration); FileCacheFactory::setPrefix(Settings::getApcuPrefix('file_cache', $this->root)); }
/** * {@inheritdoc} */ public function boot() { if ($this->booted) { return $this; } // Ensure that findSitePath is set. if (!$this->sitePath) { throw new \Exception('Kernel does not have site path set before calling boot()'); } // Initialize the FileCacheFactory component. We have to do it here instead // of in \Drupal\Component\FileCache\FileCacheFactory because we can not use // the Settings object in a component. $configuration = Settings::get('file_cache'); // Provide a default configuration, if not set. if (!isset($configuration['default'])) { $configuration['default'] = ['class' => '\\Drupal\\Component\\FileCache\\FileCache', 'cache_backend_class' => NULL, 'cache_backend_configuration' => []]; // @todo Use extension_loaded('apcu') for non-testbot // https://www.drupal.org/node/2447753. if (function_exists('apc_fetch')) { $configuration['default']['cache_backend_class'] = '\\Drupal\\Component\\FileCache\\ApcuFileCacheBackend'; } } FileCacheFactory::setConfiguration($configuration); FileCacheFactory::setPrefix(Settings::getApcuPrefix('file_cache', $this->root)); // Initialize the container. $this->initializeContainer(); // Ensure mt_rand() is reseeded to prevent random values from one page load // being exploited to predict random values in subsequent page loads. $seed = unpack("L", Crypt::randomBytes(4)); mt_srand($seed[1]); $this->booted = TRUE; return $this; }