10 use Bitrix\Main\Config\Configuration;
88 $this->backgroundJobs = new \SplPriorityQueue();
98 if (!isset(static::$instance))
99 static::$instance =
new static();
101 return static::$instance;
109 if ($this->isBasicKernelInitialized)
111 $this->isBasicKernelInitialized =
true;
130 $this->initializeSessions();
132 $this->initializeSessionLocalStorage();
135 private function initializeSessions()
138 $resolver->resolve();
140 $this->session = $resolver->getSession();
141 $this->kernelSession = $resolver->getKernelSession();
144 $this->kernelSession,
149 private function initializeSessionLocalStorage()
152 if ($cacheEngine instanceof Data\LocalStorage\Storage\CacheEngineInterface)
154 $localSessionStorage =
new Data\LocalStorage\Storage\CacheStorage($cacheEngine);
158 $localSessionStorage =
new Data\LocalStorage\Storage\NativeSessionStorage(
163 $this->sessionLocalStorageManager =
new Data\LocalStorage\SessionLocalStorageManager($localSessionStorage);
164 $configLocalStorage = Config\Configuration::getValue(
"session_local_storage") ?: [];
165 if (isset($configLocalStorage[
'ttl']))
167 $this->sessionLocalStorageManager->setTtl($configLocalStorage[
'ttl']);
238 if($response ===
null)
241 $response = $this->context->getResponse();
245 while(($c = ob_get_clean()) !==
false)
252 $response->appendContent($content);
286 \CMain::RunFinalActionsInternal();
289 session_write_close();
334 $exceptionHandling = Config\Configuration::getValue(
"exception_handling");
335 if ($exceptionHandling ==
null)
336 $exceptionHandling = array();
338 if (!isset($exceptionHandling[
"debug"]) || !is_bool($exceptionHandling[
"debug"]))
339 $exceptionHandling[
"debug"] =
false;
340 $exceptionHandler->setDebugMode($exceptionHandling[
"debug"]);
342 if (isset($exceptionHandling[
"handled_errors_types"]) && is_int($exceptionHandling[
"handled_errors_types"]))
343 $exceptionHandler->setHandledErrorsTypes($exceptionHandling[
"handled_errors_types"]);
345 if (isset($exceptionHandling[
"exception_errors_types"]) && is_int($exceptionHandling[
"exception_errors_types"]))
346 $exceptionHandler->setExceptionErrorsTypes($exceptionHandling[
"exception_errors_types"]);
348 if (isset($exceptionHandling[
"ignore_silence"]) && is_bool($exceptionHandling[
"ignore_silence"]))
349 $exceptionHandler->setIgnoreSilence($exceptionHandling[
"ignore_silence"]);
351 if (isset($exceptionHandling[
"assertion_throws_exception"]) && is_bool($exceptionHandling[
"assertion_throws_exception"]))
352 $exceptionHandler->setAssertionThrowsException($exceptionHandling[
"assertion_throws_exception"]);
354 if (isset($exceptionHandling[
"assertion_error_type"]) && is_int($exceptionHandling[
"assertion_error_type"]))
355 $exceptionHandler->setAssertionErrorType($exceptionHandling[
"assertion_error_type"]);
357 $exceptionHandler->initialize(
358 array($this,
"createExceptionHandlerOutput"),
359 array($this,
"createExceptionHandlerLog")
367 $exceptionHandling = Config\Configuration::getValue(
"exception_handling");
368 if ($exceptionHandling ===
null || !is_array($exceptionHandling) || !isset($exceptionHandling[
"log"]) || !is_array($exceptionHandling[
"log"]))
371 $options = $exceptionHandling[
"log"];
375 if (isset($options[
"class_name"]) && !empty($options[
"class_name"]))
377 if (isset($options[
"extension"]) && !empty($options[
"extension"]) && !extension_loaded($options[
"extension"]))
380 if (isset($options[
"required_file"]) && !empty($options[
"required_file"]) && ($requiredFile =
Loader::getLocal($options[
"required_file"])) !==
false)
381 require_once($requiredFile);
383 $className = $options[
"class_name"];
384 if (!class_exists($className))
387 $log =
new $className();
389 elseif (isset($options[
"settings"]) && is_array($options[
"settings"]))
399 isset($options[
"settings"]) && is_array($options[
"settings"]) ? $options[
"settings"] : array()
422 $show_cache_stat =
"";
423 if (isset($_GET[
"show_cache_stat"]))
425 $show_cache_stat = (mb_strtoupper($_GET[
"show_cache_stat"]) ==
"Y" ?
"Y" :
"");
426 @setcookie(
"show_cache_stat", $show_cache_stat,
false,
"/");
428 elseif (isset($_COOKIE[
"show_cache_stat"]))
430 $show_cache_stat = $_COOKIE[
"show_cache_stat"];
434 if (isset($_GET[
"clear_cache_session"]))
436 if (isset($_GET[
"clear_cache"]))
489 return $pool->getConnection($name);
509 if ($this->managedCache ==
null)
524 if ($this->taggedCache ==
null)
539 return $this->sessionLocalStorageManager->
get($name);
564 global $USER_FIELD_MANAGER;
565 return $USER_FIELD_MANAGER;
575 static $isUtfMode =
null;
576 if ($isUtfMode ===
null)
578 $isUtfMode = Config\Configuration::getValue(
"utf_mode");
579 if ($isUtfMode ===
null)
592 static $documentRoot =
null;
593 if ($documentRoot !=
null)
594 return $documentRoot;
601 return $documentRoot = $server->getDocumentRoot();
614 static $personalRoot =
null;
615 if ($personalRoot !=
null)
616 return $personalRoot;
623 return $personalRoot = $server->getPersonalRoot();
626 return isset($_SERVER[
"BX_PERSONAL_ROOT"]) ? $_SERVER[
"BX_PERSONAL_ROOT"] :
"/bitrix";
634 if (defined(
"BX_NO_ACCELERATOR_RESET"))
637 $fl = Config\Configuration::getValue(
"no_accelerator_reset");
641 if (function_exists(
"accelerator_reset"))
643 elseif (function_exists(
"wincache_refresh_if_changed"))
644 wincache_refresh_if_changed();
654 public function addBackgroundJob(callable $job, array $args = [], $priority = self::JOB_PRIORITY_NORMAL)
656 $this->backgroundJobs->insert([$job, $args], $priority);
663 $lastException =
null;
667 while($this->backgroundJobs->valid())
671 foreach ($this->backgroundJobs as $job)
677 foreach ($jobs as $job)
681 call_user_func_array($job[0], $job[1]);
683 catch (\Throwable $exception)
685 $lastException = $exception;
686 $exceptionHandler->writeToLog($exception);
691 if ($lastException !==
null)
693 throw $lastException;
Base class for any application.
__construct()
Creates new application instance.
handleResponseBeforeSend(Response $response)
setContext(Context $context)
Modifies context of the current request.
getCompositeSessionManager()
const JOB_PRIORITY_NORMAL
createExceptionHandlerOutput()
getManagedCache()
Returns manager of the managed cache.
setCurrentRoute(Route $currentRoute)
static getDocumentRoot()
Returns server document root.
initializeExceptionHandler()
Exception handler can be initialized through the Config\Configuration (.settings.php file).
$isBasicKernelInitialized
createDatabaseConnection()
Creates database connection pool.
getContext()
Returns context of the current request.
initializeBasicKernel()
Does minimally possible kernel initialization.
addBackgroundJob(callable $job, array $args=[], $priority=self::JOB_PRIORITY_NORMAL)
Adds a job to do after the response was sent.
static getUserTypeManager()
Returns UF manager.
getConnectionPool()
Returns database connections pool object.
$sessionLocalStorageManager
getSessionLocalStorageManager()
terminate($status=0)
Terminates application by invoking exit().
static isUtfMode()
Returns true id server is in utf-8 mode.
getTaggedCache()
Returns manager of the managed cache.
static resetAccelerator()
Resets accelerator if any.
isExtendedKernelInitialized()
getCache()
Returns new instance of the Cache object.
initializeContext(array $params)
Initializes context of the current request.
static getInstance()
Returns current instance of the Application.
static getPersonalRoot()
Returns personal root directory (relative to document root)
createExceptionHandlerLog()
$isExtendedKernelInitialized
setRouter(Router $router)
static getConnection($name="")
Static method returns database connection for the specified name.
end($status=0, Response $response=null)
Ends work of application.
initializeExtendedKernel(array $params)
Does full kernel initialization.
start()
Starts request execution.
run()
Runs controller and its action and sends response to the output.
Context of current request.
static createInstance($params=[])
static setClearCacheSession($clearCacheSession)
A privileged user wants to skip cache on this session.
static setClearCache($clearCache)
A privileged user wants to skip cache on this hit.
static setShowCacheStat($showCacheStat)
static createCacheEngine($params=[])
Connection pool is a connections holder.
static getDocumentRoot()
Returns document root.
static getLocal($path, $root=null)
Checks if file exists in /local or /bitrix directories.
static getInstance($object)