89 ServiceLocator::getInstance()->registerByGlobalSettings();
90 $this->backgroundJobs = new \SplPriorityQueue();
103 if (!isset(static::$instance))
105 static::$instance =
new static();
107 return static::$instance;
115 return isset(static::$instance);
135 if (!$this->initialized)
137 $this->initializeSessions();
138 $this->initializeSessionLocalStorage();
140 $this->initialized =
true;
144 private function initializeSessions()
147 $resolver->resolve();
149 $this->session = $resolver->getSession();
150 $this->kernelSession = $resolver->getKernelSession();
153 $this->kernelSession,
158 private function initializeSessionLocalStorage()
160 $cacheEngine = Data\Cache::createCacheEngine();
161 if ($cacheEngine instanceof Data\LocalStorage\Storage\CacheEngineInterface)
163 $localSessionStorage =
new Data\LocalStorage\Storage\CacheStorage($cacheEngine);
167 $localSessionStorage =
new Data\LocalStorage\Storage\NativeSessionStorage(
172 $this->sessionLocalStorageManager =
new Data\LocalStorage\SessionLocalStorageManager($localSessionStorage);
173 $configLocalStorage = Config\Configuration::getValue(
"session_local_storage") ?: [];
174 if (isset($configLocalStorage[
'ttl']))
176 $this->sessionLocalStorageManager->setTtl($configLocalStorage[
'ttl']);
247 if($response ===
null)
250 $response = $this->context->getResponse();
255 while(($c = ob_get_clean()) !==
false && $n > 0)
263 $response->appendContent($content);
295 \CMain::RunFinalActionsInternal();
298 session_write_close();
302 $pool->useMasterOnly(
true);
306 $pool->useMasterOnly(
false);
308 Data\ManagedCache::finalize();
344 $exceptionHandling = Config\Configuration::getValue(
"exception_handling");
345 if ($exceptionHandling ==
null)
346 $exceptionHandling = array();
348 if (!isset($exceptionHandling[
"debug"]) || !is_bool($exceptionHandling[
"debug"]))
349 $exceptionHandling[
"debug"] =
false;
350 $exceptionHandler->setDebugMode($exceptionHandling[
"debug"]);
352 if (!empty($exceptionHandling[
'track_modules']) && is_array($exceptionHandling[
'track_modules']))
354 $exceptionHandler->setTrackModules($exceptionHandling[
'track_modules']);
357 if (isset($exceptionHandling[
"handled_errors_types"]) && is_int($exceptionHandling[
"handled_errors_types"]))
358 $exceptionHandler->setHandledErrorsTypes($exceptionHandling[
"handled_errors_types"]);
360 if (isset($exceptionHandling[
"exception_errors_types"]) && is_int($exceptionHandling[
"exception_errors_types"]))
361 $exceptionHandler->setExceptionErrorsTypes($exceptionHandling[
"exception_errors_types"]);
363 if (isset($exceptionHandling[
"ignore_silence"]) && is_bool($exceptionHandling[
"ignore_silence"]))
364 $exceptionHandler->setIgnoreSilence($exceptionHandling[
"ignore_silence"]);
366 if (isset($exceptionHandling[
"assertion_throws_exception"]) && is_bool($exceptionHandling[
"assertion_throws_exception"]))
367 $exceptionHandler->setAssertionThrowsException($exceptionHandling[
"assertion_throws_exception"]);
369 if (isset($exceptionHandling[
"assertion_error_type"]) && is_int($exceptionHandling[
"assertion_error_type"]))
370 $exceptionHandler->setAssertionErrorType($exceptionHandling[
"assertion_error_type"]);
372 $exceptionHandler->initialize(
373 array($this,
"createExceptionHandlerOutput"),
374 array($this,
"createExceptionHandlerLog")
377 ServiceLocator::getInstance()->addInstance(
'exceptionHandler', $exceptionHandler);
382 $exceptionHandling = Config\Configuration::getValue(
"exception_handling");
384 if (!is_array($exceptionHandling) || !isset($exceptionHandling[
"log"]) || !is_array($exceptionHandling[
"log"]))
389 $options = $exceptionHandling[
"log"];
393 if (isset($options[
"class_name"]) && !empty($options[
"class_name"]))
395 if (isset($options[
"extension"]) && !empty($options[
"extension"]) && !extension_loaded($options[
"extension"]))
400 if (isset($options[
"required_file"]) && !empty($options[
"required_file"]) && ($requiredFile =
Loader::getLocal($options[
"required_file"])) !==
false)
402 require_once($requiredFile);
405 $className = $options[
"class_name"];
406 if (!class_exists($className))
411 $log =
new $className();
413 elseif (isset($options[
"settings"]) && is_array($options[
"settings"]))
423 isset($options[
"settings"]) && is_array($options[
"settings"]) ? $options[
"settings"] : array()
446 $show_cache_stat =
"";
447 if (isset($_GET[
"show_cache_stat"]))
449 $show_cache_stat = (strtoupper($_GET[
"show_cache_stat"]) ==
"Y" ?
"Y" :
"");
450 @setcookie(
"show_cache_stat", $show_cache_stat,
false,
"/");
452 elseif (isset($_COOKIE[
"show_cache_stat"]))
454 $show_cache_stat = $_COOKIE[
"show_cache_stat"];
456 Data\Cache::setShowCacheStat($show_cache_stat ===
"Y");
458 if (isset($_GET[
"clear_cache_session"]))
459 Data\Cache::setClearCacheSession($_GET[
"clear_cache_session"] ===
'Y');
460 if (isset($_GET[
"clear_cache"]))
461 Data\Cache::setClearCache($_GET[
"clear_cache"] ===
'Y');
469 return ServiceLocator::getInstance()->get(
'exceptionHandler');
506 $this->license =
new License();
523 return $pool->getConnection($name);
533 return Data\Cache::createInstance();
543 if ($this->managedCache ==
null)
558 if ($this->taggedCache ==
null)
573 return $this->sessionLocalStorageManager->
get($name);
598 global $USER_FIELD_MANAGER;
599 return $USER_FIELD_MANAGER;
609 static $isUtfMode =
null;
610 if ($isUtfMode ===
null)
612 $isUtfMode = Config\Configuration::getValue(
"utf_mode");
613 if ($isUtfMode ===
null)
626 static $documentRoot =
null;
627 if ($documentRoot !=
null)
628 return $documentRoot;
635 return $documentRoot = $server->getDocumentRoot();
648 static $personalRoot =
null;
649 if ($personalRoot !=
null)
650 return $personalRoot;
657 return $personalRoot = $server->getPersonalRoot();
660 return $_SERVER[
"BX_PERSONAL_ROOT"] ??
'/bitrix';
668 if (defined(
"BX_NO_ACCELERATOR_RESET"))
671 $fl = Config\Configuration::getValue(
"no_accelerator_reset");
675 if (function_exists(
"accelerator_reset"))
677 elseif (function_exists(
"wincache_refresh_if_changed"))
678 wincache_refresh_if_changed();
688 public function addBackgroundJob(callable $job, array $args = [], $priority = self::JOB_PRIORITY_NORMAL)
690 $this->backgroundJobs->insert([$job, $args], $priority);
697 $lastException =
null;
701 while($this->backgroundJobs->valid())
705 foreach ($this->backgroundJobs as $job)
711 foreach ($jobs as $job)
715 call_user_func_array($job[0], $job[1]);
717 catch (\Throwable $exception)
719 $lastException = $exception;
720 $exceptionHandler->writeToLog($exception);
725 if ($lastException !==
null)
727 throw $lastException;
handleResponseBeforeSend(Response $response)
setContext(Context $context)
getCompositeSessionManager()
const JOB_PRIORITY_NORMAL
createExceptionHandlerOutput()
setCurrentRoute(Route $currentRoute)
initializeExceptionHandler()
createDatabaseConnection()
addBackgroundJob(callable $job, array $args=[], $priority=self::JOB_PRIORITY_NORMAL)
static getUserTypeManager()
$sessionLocalStorageManager
getSessionLocalStorageManager()
static resetAccelerator()
initializeContext(array $params)
createExceptionHandlerLog()
setRouter(Router $router)
static getConnection($name="")
end($status=0, Response $response=null)
initializeExtendedKernel(array $params)
static getLocal($path, $root=null)