85 ServiceLocator::getInstance()->registerByGlobalSettings();
86 $this->backgroundJobs = new \SplPriorityQueue();
100 if (!isset(static::$instance))
102 static::$instance =
new static();
104 return static::$instance;
112 return isset(static::$instance);
132 if (!$this->initialized)
134 $this->initializeSessions();
135 $this->initializeSessionLocalStorage();
137 $this->initialized =
true;
141 private function initializeSessions()
144 $resolver->resolve();
146 $this->session = $resolver->getSession();
147 $this->kernelSession = $resolver->getKernelSession();
150 $this->kernelSession,
155 private function initializeSessionLocalStorage()
157 $cacheEngine = Data\Cache::createCacheEngine();
158 if ($cacheEngine instanceof Data\LocalStorage\Storage\CacheEngineInterface)
160 $localSessionStorage =
new Data\LocalStorage\Storage\CacheStorage($cacheEngine);
164 $localSessionStorage =
new Data\LocalStorage\Storage\NativeSessionStorage(
169 $this->sessionLocalStorageManager =
new Data\LocalStorage\SessionLocalStorageManager($localSessionStorage);
170 $configLocalStorage = Config\Configuration::getValue(
"session_local_storage") ?: [];
171 if (isset($configLocalStorage[
'ttl']))
173 $this->sessionLocalStorageManager->setTtl($configLocalStorage[
'ttl']);
182 if ($this->router ===
null)
208 return isset($this->currentRoute);
231 $routingConfig = Configuration::getInstance()->get(
'routing');
232 $documentRoot = $this->context->getServer()->getDocumentRoot();
234 if (!empty($routingConfig[
'config']))
236 $fileNames = $routingConfig[
'config'];
240 foreach ([
'local',
'bitrix'] as $vendor)
253 if (file_exists(
$documentRoot .
'/bitrix/routes/web_bitrix.php'))
260 $callback = include $file;
310 $response = $this->context->getResponse();
315 while (($c = ob_get_clean()) !==
false &&
$n > 0)
362 if ($this->terminating)
368 $this->terminating =
true;
371 \CMain::RunFinalActionsInternal();
374 session_write_close();
378 $pool->useMasterOnly(
true);
382 $pool->useMasterOnly(
false);
420 $exceptionHandling = Config\Configuration::getValue(
"exception_handling");
421 if ($exceptionHandling ==
null)
423 $exceptionHandling = [];
426 if (!isset($exceptionHandling[
"debug"]) || !is_bool($exceptionHandling[
"debug"]))
428 $exceptionHandling[
"debug"] =
false;
430 $exceptionHandler->setDebugMode($exceptionHandling[
"debug"]);
432 if (!empty($exceptionHandling[
'track_modules']) && is_array($exceptionHandling[
'track_modules']))
434 $exceptionHandler->setTrackModules($exceptionHandling[
'track_modules']);
437 if (isset($exceptionHandling[
"handled_errors_types"]) && is_int($exceptionHandling[
"handled_errors_types"]))
439 $exceptionHandler->setHandledErrorsTypes($exceptionHandling[
"handled_errors_types"]);
442 if (isset($exceptionHandling[
"exception_errors_types"]) && is_int($exceptionHandling[
"exception_errors_types"]))
444 $exceptionHandler->setExceptionErrorsTypes($exceptionHandling[
"exception_errors_types"]);
447 if (isset($exceptionHandling[
"ignore_silence"]) && is_bool($exceptionHandling[
"ignore_silence"]))
449 $exceptionHandler->setIgnoreSilence($exceptionHandling[
"ignore_silence"]);
452 if (isset($exceptionHandling[
"assertion_throws_exception"]) && is_bool($exceptionHandling[
"assertion_throws_exception"]))
454 $exceptionHandler->setAssertionThrowsException($exceptionHandling[
"assertion_throws_exception"]);
457 if (isset($exceptionHandling[
"assertion_error_type"]) && is_int($exceptionHandling[
"assertion_error_type"]))
459 $exceptionHandler->setAssertionErrorType($exceptionHandling[
"assertion_error_type"]);
462 $exceptionHandler->initialize(
463 [$this,
"createExceptionHandlerOutput"],
464 [$this,
"createExceptionHandlerLog"]
467 ServiceLocator::getInstance()->addInstance(
'exceptionHandler', $exceptionHandler);
472 $exceptionHandling = Config\Configuration::getValue(
"exception_handling");
474 if (!is_array($exceptionHandling) || !isset($exceptionHandling[
"log"]) || !is_array($exceptionHandling[
"log"]))
479 $options = $exceptionHandling[
"log"];
485 if (!empty(
$options[
"extension"]) && !extension_loaded(
$options[
"extension"]))
492 require_once($requiredFile);
495 $className =
$options[
"class_name"];
496 if (!class_exists($className))
501 $log =
new $className();
536 $show_cache_stat =
"";
537 if (isset($_GET[
"show_cache_stat"]))
539 $show_cache_stat = (strtoupper($_GET[
"show_cache_stat"]) ==
"Y" ?
"Y" :
"");
540 @setcookie(
"show_cache_stat", $show_cache_stat,
false,
"/");
542 elseif (isset($_COOKIE[
"show_cache_stat"]))
544 $show_cache_stat = $_COOKIE[
"show_cache_stat"];
546 Data\Cache::setShowCacheStat($show_cache_stat ===
"Y");
548 if (isset($_GET[
"clear_cache_session"]))
550 Data\Cache::setClearCacheSession($_GET[
"clear_cache_session"] ===
'Y');
552 if (isset($_GET[
"clear_cache"]))
554 Data\Cache::setClearCache($_GET[
"clear_cache"] ===
'Y');
560 $config = Config\Configuration::getValue(
'messenger');
564 $config = [
'run_mode' => WorkerRunMode::BackgroundInWeb->value];
567 if (!isset(
$config[
'run_mode']))
569 $config[
'run_mode'] = WorkerRunMode::BackgroundInWeb->value;
587 return ServiceLocator::getInstance()->get(
'exceptionHandler');
624 $this->license =
new License();
641 return $pool->getConnection(
$name);
651 return Data\Cache::createInstance();
661 if ($this->managedCache ==
null)
676 if ($this->taggedCache ==
null)
691 return $this->sessionLocalStorageManager->get(
$name);
764 static $personalRoot =
null;
765 if ($personalRoot !=
null)
767 return $personalRoot;
776 return $personalRoot = $server->getPersonalRoot();
780 return $_SERVER[
"BX_PERSONAL_ROOT"] ??
'/bitrix';
788 if (defined(
"BX_NO_ACCELERATOR_RESET"))
793 if (
Config\Configuration::getValue(
"no_accelerator_reset"))
798 if (function_exists(
"opcache_reset"))
820 $this->backgroundJobs->insert([$job, $args], $priority);
827 $lastException =
null;
831 while ($this->backgroundJobs->valid())
835 foreach ($this->backgroundJobs as $job)
841 foreach ($jobs as $job)
845 call_user_func_array($job[0], $job[1]);
847 catch (\Throwable $exception)
849 $lastException = $exception;
850 $exceptionHandler->writeToLog($exception);
855 if ($lastException !==
null)
857 throw $lastException;
handleResponseBeforeSend(Response $response)
setContext(Context $context)
getCompositeSessionManager()
static resetAccelerator(string $filename=null)
const JOB_PRIORITY_NORMAL
createExceptionHandlerOutput()
initializeMessengerWorker()
setCurrentRoute(Route $currentRoute)
initializeExceptionHandler()
createDatabaseConnection()
addBackgroundJob(callable $job, array $args=[], $priority=self::JOB_PRIORITY_NORMAL)
static getUserTypeManager()
$sessionLocalStorageManager
getSessionLocalStorageManager()
initializeContext(array $params)
createExceptionHandlerLog()
setRouter(Router $router)
static getConnection($name="")
end($status=0, Response $response=null)
initializeExtendedKernel(array $params)
static getLocal($path, $root=null)
static handle($files, $router)
foreach(['Bitrix\\Main'=> '/lib', 'Psr\\Container'=> '/vendor/psr/container/src', 'Psr\\Log'=> '/vendor/psr/log/src', 'Psr\\Http\\Message'=> '/vendor/psr/http-message/src', 'Psr\\Http\\Client'=> '/vendor/psr/http-client/src', 'Http\\Promise'=> '/vendor/php-http/promise/src', 'PHPMailer\\PHPMailer'=> '/vendor/phpmailer/phpmailer/src', 'GeoIp2'=> '/vendor/geoip2/geoip2/src', 'MaxMind\\Db'=> '/vendor/maxmind-db/reader/src/MaxMind/Db', 'PhpParser'=> '/vendor/nikic/php-parser/lib/PhpParser', 'Recurr'=> '/vendor/simshaun/recurr/src/Recurr',] as $namespace=> $namespacePath) $documentRoot
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)