/** * Returns the file size. * * @return float|int * @throws FileNotFoundException * @throws FileOpenException */ public function getSize() { if (!$this->isExists()) { throw new FileNotFoundException($this->originalPath); } static $supportLarge32 = null; if ($supportLarge32 === null) { $supportLarge32 = \Bitrix\Main\Config\Configuration::getValue("large_files_32bit_support") === true; } $size = 0; if (PHP_INT_SIZE < 8 && $supportLarge32) { // 32bit $this->open(FileStreamOpenMode::READ); if (fseek($this->filePointer, 0, SEEK_END) === 0) { $size = 0.0; $step = 0x7fffffff; while ($step > 0) { if (fseek($this->filePointer, -$step, SEEK_CUR) === 0) { $size += floatval($step); } else { $step >>= 1; } } } $this->close(); } else { // 64bit $size = filesize($this->getPhysicalPath()); } return $size; }
public function __construct() { if (self::$obMemcache == null) { self::$obMemcache = new \Memcache(); $cacheConfig = Config\Configuration::getValue("cache"); $v = isset($cacheConfig["memcache"]) ? $cacheConfig["memcache"] : null; if ($v != null && isset($v["host"]) && $v["host"] != "") { if ($v != null && isset($v["port"])) { $port = intval($v["port"]); } else { $port = 11211; } if (self::$obMemcache->connect($v["host"], $port)) { self::$isConnected = true; register_shutdown_function(array("\\Bitrix\\Main\\Data\\CacheEngineMemcache", "close")); } } } $v = Config\Configuration::getValue("cache"); if ($v != null && isset($v["sid"]) && $v["sid"] != "") { $this->sid = $v["sid"]; } else { $this->sid = "BX"; } }
private static function getInstance() { if (self::$instance) { return self::$instance; } $loader = new BitrixLoader($_SERVER['DOCUMENT_ROOT']); $c = Configuration::getInstance(); $config = $c->get('maximaster'); $twigConfig = (array) $config['tools']['twig']; $defaultConfig = array('debug' => false, 'charset' => SITE_CHARSET, 'cache' => $_SERVER['DOCUMENT_ROOT'] . '/bitrix/cache/maximaster/tools.twig', 'auto_reload' => isset($_GET['clear_cache']) && strtoupper($_GET['clear_cache']) == 'Y', 'autoescape' => false); $twigOptions = array_merge($defaultConfig, $twigConfig); $twig = new \Twig_Environment($loader, $twigOptions); if ($twig->isDebug()) { $twig->addExtension(new \Twig_Extension_Debug()); } $twig->addExtension(new BitrixExtension()); $twig->addExtension(new CustomFunctionsExtension()); $event = new Event('', 'onAfterTwigTemplateEngineInited', array($twig)); $event->send(); if ($event->getResults()) { foreach ($event->getResults() as $evenResult) { if ($evenResult->getType() == \Bitrix\Main\EventResult::SUCCESS) { $twig = current($evenResult->getParameters()); } } } return self::$instance = $twig; }
public function getOptions() { $c = Configuration::getInstance(); $config = $c->get('maximaster'); $twigConfig = (array) $config['tools']['twig']; $this->options = array_merge($this->getDefaultOptions(), $twigConfig); return $this->options; }
public function __construct() { $v = \Bitrix\Main\Config\Configuration::getValue("cache"); if ($v != null && isset($v["sid"]) && $v["sid"] != "") { $this->sid = $v["sid"]; } else { $this->sid = "BX"; } }
/** * Constructor. * * @param string $connectionName * * @throws Exception */ public function __construct($connectionName = 'default') { $connections = Configuration::getInstance()->get('connections'); if (!array_key_exists($connectionName, $connections)) { throw new Exception("Connection '{$connectionName}' is not found in .settings.php"); } $connection = $connections[$connectionName]; parent::__construct("mysql:dbname={$connection['database']};host={$connection['host']}", $connection['login'], $connection['password']); }
public function setStatus($status) { $httpStatus = \Bitrix\Main\Config\Configuration::getValue("http_status"); $cgiMode = stristr(php_sapi_name(), "cgi") !== false; if ($cgiMode && ($httpStatus == null || $httpStatus == false)) { $this->addHeader("Status", $status); } else { $server = $this->context->getServer(); $this->addHeader($server->get("SERVER_PROTOCOL") . " " . $status); } }
function SaveConfig($arServerList) { self::$arList = false; $isOnline = false; $content = '<' . '? define("BX_MEMCACHE_CLUSTER", "' . EscapePHPString(CMain::GetServerUniqID()) . '"); $arList = array( '; $defGroup = 1; $arGroups = array(); $rsGroups = CClusterGroup::GetList(array("ID" => "DESC")); while ($arGroup = $rsGroups->Fetch()) { $defGroup = $arGroups[$arGroup["ID"]] = intval($arGroup["ID"]); } foreach ($arServerList as $i => $arServer) { $isOnline |= $arServer["STATUS"] == "ONLINE"; $GROUP_ID = intval($arServer["GROUP_ID"]); if (!array_key_exists($arServer["GROUP_ID"], $arGroups)) { $GROUP_ID = $defGroup; } $content .= "\t" . intval($i) . " => array(\n"; $content .= "\t\t'ID' => \"" . EscapePHPString($arServer["ID"]) . "\",\n"; $content .= "\t\t'GROUP_ID' => " . $GROUP_ID . ",\n"; $content .= "\t\t'HOST' => \"" . EscapePHPString($arServer["HOST"]) . "\",\n"; $content .= "\t\t'PORT' => " . intval($arServer["PORT"]) . ",\n"; $content .= "\t\t'WEIGHT' => " . intval($arServer["WEIGHT"]) . ",\n"; if ($arServer["STATUS"] == "ONLINE") { $content .= "\t\t'STATUS' => \"ONLINE\",\n"; } elseif ($arServer["STATUS"] == "OFFLINE") { $content .= "\t\t'STATUS' => \"OFFLINE\",\n"; } else { $content .= "\t\t'STATUS' => \"READY\",\n"; } $content .= "\t),\n"; } $content .= '); ?' . '>'; file_put_contents($_SERVER["DOCUMENT_ROOT"] . BX_ROOT . "/modules/cluster/memcache.php", $content); bx_accelerator_reset(); self::$systemConfigurationUpdate = null; $cache = \Bitrix\Main\Config\Configuration::getValue('cache'); if ($isOnline) { if (!is_array($cache) || !isset($cache['type']) || !is_array($cache['type']) || !isset($cache['type']['class_name']) || !$cache['type']['class_name'] === 'CPHPCacheMemcacheCluster') { \Bitrix\Main\Config\Configuration::setValue('cache', array('type' => array('class_name' => 'CPHPCacheMemcacheCluster', 'extension' => 'memcache', 'required_file' => 'modules/cluster/classes/general/memcache_cache.php'))); self::$systemConfigurationUpdate = true; } } else { if (is_array($cache) && isset($cache['type']) && is_array($cache['type']) && isset($cache['type']['class_name']) && $cache['type']['class_name'] === 'CPHPCacheMemcacheCluster') { \Bitrix\Main\Config\Configuration::setValue('cache', null); self::$systemConfigurationUpdate = false; } } }
/** * Load a configuration for the loggers from `.settings.php` or `.settings_extra.php`. * * @param bool $force Load even if the configuration has already been loaded. * * @return bool */ public static function loadConfiguration($force = false) { if ($force === false && static::$isConfigurationLoaded === true) { return true; } if (class_exists('\\Bitrix\\Main\\Config\\Configuration')) { $config = Configuration::getInstance()->get('monolog'); if (is_array($config) && !empty($config)) { Cascade::fileConfig($config); return true; } } return false; }
/** * Search connection parameters (type, host, db, login and password) by connection name * * @param string $name Connection name * @return array|null * @throws \Bitrix\Main\ArgumentTypeException * @throws \Bitrix\Main\ArgumentNullException */ private function searchConnectionParametersByName($name) { if (!is_string($name)) { throw new \Bitrix\Main\ArgumentTypeException("name", "string"); } if ($name === "") { throw new \Bitrix\Main\ArgumentNullException("name"); } $connectionsConfiguration = \Bitrix\Main\Config\Configuration::getValue('connections'); if (isset($connectionsConfiguration[$name])) { return $connectionsConfiguration[$name]; } /* TODO: exception, if config not found */ return null; }
public static function getCurrentTemplateId($siteId) { $cacheFlags = Config\Configuration::getValue("cache_flags"); $ttl = isset($cacheFlags["site_template"]) ? $cacheFlags["site_template"] : 0; $connection = Application::getConnection(); $sqlHelper = $connection->getSqlHelper(); $field = $connection->getType() === "mysql" ? "`CONDITION`" : "CONDITION"; $path2templates = IO\Path::combine(Application::getDocumentRoot(), Application::getPersonalRoot(), "templates"); if ($ttl === false) { $sql = "\n\t\t\t\tSELECT " . $field . ", TEMPLATE\n\t\t\t\tFROM b_site_template\n\t\t\t\tWHERE SITE_ID = '" . $sqlHelper->forSql($siteId) . "'\n\t\t\t\tORDER BY IF(LENGTH(" . $field . ") > 0, 1, 2), SORT\n\t\t\t\t"; $recordset = $connection->query($sql); while ($record = $recordset->fetch()) { $condition = trim($record["CONDITION"]); if ($condition != '' && !@eval("return " . $condition . ";")) { continue; } if (IO\Directory::isDirectoryExists($path2templates . "/" . $record["TEMPLATE"])) { return $record["TEMPLATE"]; } } } else { $managedCache = Application::getInstance()->getManagedCache(); if ($managedCache->read($ttl, "b_site_template")) { $arSiteTemplateBySite = $managedCache->get("b_site_template"); } else { $arSiteTemplateBySite = array(); $sql = "\n\t\t\t\t\tSELECT " . $field . ", TEMPLATE, SITE_ID\n\t\t\t\t\tFROM b_site_template\n\t\t\t\t\tWHERE SITE_ID = '" . $sqlHelper->forSql($siteId) . "'\n\t\t\t\t\tORDER BY SITE_ID, IF(LENGTH(" . $field . ") > 0, 1, 2), SORT\n\t\t\t\t\t"; $recordset = $connection->query($sql); while ($record = $recordset->fetch()) { $arSiteTemplateBySite[$record['SITE_ID']][] = $record; } $managedCache->set("b_site_template", $arSiteTemplateBySite); } if (is_array($arSiteTemplateBySite[$siteId])) { foreach ($arSiteTemplateBySite[$siteId] as $record) { $condition = trim($record["CONDITION"]); if ($condition != '' && !@eval("return " . $condition . ";")) { continue; } if (IO\Directory::isDirectoryExists($path2templates . "/" . $record["TEMPLATE"])) { return $record["TEMPLATE"]; } } } } return ".default"; }
protected function getCookieDomain() { static $bCache = false; static $cache = false; if ($bCache) { return $cache; } $context = Application::getInstance()->getContext(); $server = $context->getServer(); $cacheFlags = \Bitrix\Main\Config\Configuration::getValue("cache_flags"); $cacheTtl = isset($cacheFlags["site_domain"]) ? $cacheFlags["site_domain"] : 0; if ($cacheTtl === false) { $connection = Application::getDbConnection(); $sqlHelper = $connection->getSqlHelper(); $sql = "SELECT DOMAIN " . "FROM b_lang_domain " . "WHERE '" . $sqlHelper->forSql('.' . $server->getHttpHost()) . "' like " . $sqlHelper->getConcatFunction("'%.'", "DOMAIN") . " " . "ORDER BY " . $sqlHelper->getLengthFunction("DOMAIN") . " "; $recordset = $connection->query($sql); if ($record = $recordset->fetch()) { $cache = $record['DOMAIN']; } } else { $managedCache = Application::getInstance()->getManagedCache(); if ($managedCache->read($cacheTtl, "b_lang_domain", "b_lang_domain")) { $arLangDomain = $managedCache->get("b_lang_domain"); } else { $arLangDomain = array("DOMAIN" => array(), "LID" => array()); $connection = Application::getDbConnection(); $sqlHelper = $connection->getSqlHelper(); $recordset = $connection->query("SELECT * " . "FROM b_lang_domain " . "ORDER BY " . $sqlHelper->getLengthFunction("DOMAIN")); while ($record = $recordset->fetch()) { $arLangDomain["DOMAIN"][] = $record; $arLangDomain["LID"][$record["LID"]][] = $record; } $managedCache->set("b_lang_domain", $arLangDomain); } foreach ($arLangDomain["DOMAIN"] as $domain) { if (strcasecmp(substr('.' . $server->getHttpHost(), -(strlen($domain['DOMAIN']) + 1)), "." . $domain['DOMAIN']) == 0) { $cache = $domain['DOMAIN']; break; } } } $bCache = true; return $cache; }
public function __construct() { if (self::$obMemcache == null) { self::$obMemcache = new \Memcache(); $cacheConfig = Config\Configuration::getValue("cache"); $v = isset($cacheConfig["memcache"]) ? $cacheConfig["memcache"] : null; if ($v != null && isset($v["host"]) && $v["host"] != "") { if ($v != null && isset($v["port"])) { $port = intval($v["port"]); } else { $port = 11211; } if (self::$obMemcache->pconnect($v["host"], $port)) { self::$isConnected = true; } } } $v = Config\Configuration::getValue("cache"); if ($v != null && isset($v["sid"]) && $v["sid"] != "") { $this->sid = $v["sid"]; } else { $this->sid = "BX"; } }
<?php /** * Created by PhpStorm. * User: Abai Adelshin * www.orendev.ru */ use Bitrix\Main\Localization\Loc; if (!check_bitrix_sessid()) { return; } #работа с .settings.php $install_count = \Bitrix\Main\Config\Configuration::getInstance()->get('adelshin_module_person'); $cache_type = \Bitrix\Main\Config\Configuration::getInstance()->get('cache'); // считаем данный из файла .settings.php секция 'cache' #работа с .settings.php Loc::loadMessages(__FILE__); if ($ex = $APPLICATION->GetException()) { //получаем обЪект который содержит последние ошибки echo CAdminMessage::ShowMessage(array("TYPE" => "ERROR", "MESSAGE" => Loc::getMessage("MOD_INST_ERR"), "DETAILS" => $ex->GetString(), "HTML" => true)); } else { echo CAdminMessage::ShowNote(Loc::getMessage("MOD_INST_OK")); } #работа с .settings.php echo CAdminMessage::ShowMessage(array("MESSAGE" => Loc::getMessage("ADELSHIN_PERSON_INSTALL_COUNT") . $install_count['install'], "TYPE" => "OK")); if (!$cache_type['type'] || $cache_type['type'] == 'none') { // проверим секцию 'cache' подсекцию 'type' - если ее нет или установлена none выведем сообщение, что кеширование не настроено echo CAdminMessage::ShowMessage(array("MESSAGE" => Loc::getMessage("ADELSHIN_PERSON_NO_CACHE"), "TYPE" => "ERROR")); } #работа с .settings.php ?>
protected static function getDirectoryIndexArray() { static $directoryIndexDefault = array("index.php" => 1, "index.html" => 1, "index.htm" => 1, "index.phtml" => 1, "default.html" => 1, "index.php3" => 1); $directoryIndex = Main\Config\Configuration::getValue("directory_index"); if ($directoryIndex !== null) { return $directoryIndex; } return $directoryIndexDefault; }
/** * Resets accelerator if any. */ public static function resetAccelerator() { $fl = \Bitrix\Main\Config\Configuration::getValue("NoAcceleratorReset"); if ($fl) { return; } if (function_exists("accelerator_reset")) { accelerator_reset(); } elseif (function_exists("wincache_refresh_if_changed")) { wincache_refresh_if_changed(); } }
protected function updateDigest($userId, $password) { if (empty($userId)) { throw new Main\ArgumentNullException("userId"); } if (!Main\Type\Int::isInteger($userId)) { throw new Main\ArgumentTypeException("userId"); } $userId = intval($userId); $connection = Main\Application::getDbConnection(); $sqlHelper = $connection->getSqlHelper(); $recordset = $connection->query("SELECT U.LOGIN, UD.DIGEST_HA1 " . "FROM b_user U " . " LEFT JOIN b_user_digest UD on U.ID = UD.USER_ID " . "WHERE U.ID = " . $userId); if ($record = $recordset->fetch()) { $realm = Main\Config\Configuration::getValue("http_auth_realm"); if (is_null($realm)) { $realm = "Bitrix Site Manager"; } $digest = md5($record["LOGIN"] . ':' . $realm . ':' . $password); if ($record["DIGEST_HA1"] == '') { //new digest $connection->queryExecute("INSERT INTO b_user_digest (USER_ID, DIGEST_HA1) " . "VALUES('" . $userId . "', '" . $sqlHelper->forSql($digest) . "')"); } else { //update digest (login, password or realm were changed) if ($record["DIGEST_HA1"] !== $digest) { $connection->queryExecute("UPDATE b_user_digest SET " . " DIGEST_HA1 = '" . $sqlHelper->forSql($digest) . "' " . "WHERE USER_ID = " . $userId); } } } }
private static function getCacheTtl() { $cacheFlags = Configuration::getValue("cache_flags"); if (!isset($cacheFlags["config_options"])) { return 0; } return $cacheFlags["config_options"]; }
protected function initializeExceptionHandler() { $exceptionHandler = new Diag\ExceptionHandler(); $exceptionHandling = Config\Configuration::getValue("exception_handling"); if ($exceptionHandling == null) { $exceptionHandling = array(); } if (!isset($exceptionHandling["debug"]) || !is_bool($exceptionHandling["debug"])) { $exceptionHandling["debug"] = false; } $exceptionHandler->setDebugMode($exceptionHandling["debug"]); if (isset($exceptionHandling["handled_errors_types"]) && is_int($exceptionHandling["handled_errors_types"])) { $exceptionHandler->setHandledErrorsTypes($exceptionHandling["handled_errors_types"]); } if (isset($exceptionHandling["exception_errors_types"]) && is_int($exceptionHandling["exception_errors_types"])) { $exceptionHandler->setExceptionErrorsTypes($exceptionHandling["exception_errors_types"]); } if (isset($exceptionHandling["ignore_silence"]) && is_bool($exceptionHandling["ignore_silence"])) { $exceptionHandler->setIgnoreSilence($exceptionHandling["ignore_silence"]); } if (isset($exceptionHandling["assertion_throws_exception"]) && is_bool($exceptionHandling["assertion_throws_exception"])) { $exceptionHandler->setAssertionThrowsException($exceptionHandling["assertion_throws_exception"]); } if (isset($exceptionHandling["assertion_error_type"]) && is_int($exceptionHandling["assertion_error_type"])) { $exceptionHandler->setAssertionErrorType($exceptionHandling["assertion_error_type"]); } $exceptionHandlerOutput = $this->createExceptionHandlerOutput(); $exceptionHandlerLog = $this->createExceptionHandlerLog(isset($exceptionHandling["log"]) && is_array($exceptionHandling["log"]) ? $exceptionHandling["log"] : array()); $exceptionHandler->initialize($exceptionHandlerOutput, $exceptionHandlerLog); $this->exceptionHandler = $exceptionHandler; }
public static function wnc() { $configuration = Configuration::getInstance(); $configuration->loadConfiguration(); $ar = array("utf_mode" => array("value" => defined('BX_UTF'), "readonly" => true), "default_charset" => array("value" => defined('BX_DEFAULT_CHARSET'), "readonly" => false), "no_accelerator_reset" => array("value" => defined('BX_NO_ACCELERATOR_RESET'), "readonly" => false), "http_status" => array("value" => defined('BX_HTTP_STATUS') && BX_HTTP_STATUS ? true : false, "readonly" => false)); $cache = array(); if (defined('BX_CACHE_SID')) { $cache["sid"] = BX_CACHE_SID; } if (file_exists($_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/cluster/memcache.php")) { $arList = null; include $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/cluster/memcache.php"; if (defined("BX_MEMCACHE_CLUSTER") && is_array($arList)) { foreach ($arList as $listKey => $listVal) { $bOtherGroup = defined("BX_CLUSTER_GROUP") && $listVal["GROUP_ID"] !== BX_CLUSTER_GROUP; if ($listVal["STATUS"] !== "ONLINE" || $bOtherGroup) { unset($arList[$listKey]); } } if (count($arList) > 0) { $cache["type"] = array("extension" => "memcache", "required_file" => "modules/cluster/classes/general/memcache_cache.php", "class_name" => "CPHPCacheMemcacheCluster"); } } } if (!isset($cache["type"])) { if (defined('BX_CACHE_TYPE')) { $cache["type"] = BX_CACHE_TYPE; switch ($cache["type"]) { case "memcache": case "CPHPCacheMemcache": $cache["type"] = "memcache"; break; case "eaccelerator": case "CPHPCacheEAccelerator": $cache["type"] = "eaccelerator"; break; case "apc": case "CPHPCacheAPC": $cache["type"] = "apc"; break; case "xcache": case "CPHPCacheXCache": $cache["type"] = array("extension" => "xcache", "required_file" => "modules/main/classes/general/cache_xcache.php", "class_name" => "CPHPCacheXCache"); break; default: if (defined("BX_CACHE_CLASS_FILE") && file_exists(BX_CACHE_CLASS_FILE)) { $cache["type"] = array("required_remote_file" => BX_CACHE_CLASS_FILE, "class_name" => BX_CACHE_TYPE); } else { $cache["type"] = "files"; } break; } } else { $cache["type"] = "files"; } } if (defined("BX_MEMCACHE_PORT")) { $cache["memcache"]["port"] = intval(BX_MEMCACHE_PORT); } if (defined("BX_MEMCACHE_HOST")) { $cache["memcache"]["host"] = BX_MEMCACHE_HOST; } $ar["cache"] = array("value" => $cache, "readonly" => false); $cacheFlags = array(); $arCacheConsts = array("CACHED_b_option" => "config_options", "CACHED_b_lang_domain" => "site_domain"); foreach ($arCacheConsts as $const => $name) { $cacheFlags[$name] = defined($const) ? constant($const) : 0; } $ar["cache_flags"] = array("value" => $cacheFlags, "readonly" => false); $ar["cookies"] = array("value" => array("secure" => false, "http_only" => true), "readonly" => false); $ar["exception_handling"] = array("value" => array("debug" => true, "handled_errors_types" => E_ALL & ~E_NOTICE & ~E_STRICT & ~E_USER_NOTICE, "exception_errors_types" => E_ALL & ~E_NOTICE & ~E_WARNING & ~E_STRICT & ~E_USER_NOTICE & ~E_USER_WARNING & ~E_COMPILE_WARNING, "ignore_silence" => false, "assertion_throws_exception" => true, "assertion_error_type" => E_USER_ERROR, "log" => array("settings" => array("file" => "bitrix/modules/error.log", "log_size" => 1000000))), "readonly" => false); global $DBType, $DBHost, $DBName, $DBLogin, $DBPassword; $DBType = strtolower($DBType); if ($DBType == 'mysql') { $dbClassName = "\\Bitrix\\Main\\DB\\MysqlConnection"; } elseif ($DBType == 'mssql') { $dbClassName = "\\Bitrix\\Main\\DB\\MssqlConnection"; } else { $dbClassName = "\\Bitrix\\Main\\DB\\OracleConnection"; } $ar['connections']['value']['default'] = array('className' => $dbClassName, 'host' => $DBHost, 'database' => $DBName, 'login' => $DBLogin, 'password' => $DBPassword, 'options' => (!defined("DBPersistent") || DBPersistent ? 1 : 0) | (defined("DELAY_DB_CONNECT") && DELAY_DB_CONNECT === true ? 2 : 0)); $ar['connections']['readonly'] = true; foreach ($ar as $k => $v) { if ($configuration->get($k) === null) { if ($v["readonly"]) { $configuration->addReadonly($k, $v["value"]); } else { $configuration->add($k, $v["value"]); } } } $configuration->saveConfiguration(); $filename1 = $_SERVER["DOCUMENT_ROOT"] . "/bitrix/php_interface/after_connect.php"; $filename2 = $_SERVER["DOCUMENT_ROOT"] . "/bitrix/php_interface/after_connect_d7.php"; if (file_exists($filename1) && !file_exists($filename2)) { $source = file_get_contents($filename1); $source = trim($source); $pos = 2; if (strtolower(substr($source, 0, 5)) == '<?php') { $pos = 5; } $source = substr($source, 0, $pos) . "\n" . '$connection = \\Bitrix\\Main\\Application::getConnection();' . substr($source, $pos); $source = preg_replace("#\\\$DB->Query\\(#i", "\$connection->queryExecute(", $source); file_put_contents($filename2, $source); } }
/** * @return Cache */ public static function createInstance() { $cacheEngine = null; // Events can't be used here because events use cache $cacheType = "files"; $v = \Bitrix\Main\Config\Configuration::getValue("cache"); if ($v != null && isset($v["type"]) && !empty($v["type"])) { $cacheType = $v["type"]; } if (is_array($cacheType)) { if (isset($cacheType["class_name"])) { if (!isset($cacheType["extension"]) || extension_loaded($cacheType["extension"])) { if (isset($cacheType["required_file"]) && ($requiredFile = \Bitrix\Main\Loader::getLocal($cacheType["required_file"]))) { require_once $requiredFile; } $className = $cacheType["class_name"]; if (class_exists($className)) { $cacheEngine = new $className(); } } } } else { switch ($cacheType) { case "memcache": if (extension_loaded('memcache')) { $cacheEngine = new CacheEngineMemcache(); } break; case "eaccelerator": if (extension_loaded('eaccelerator')) { $cacheEngine = new CacheEngineEAccelerator(); } break; case "apc": if (extension_loaded('apc')) { $cacheEngine = new CacheEngineApc(); } break; case "files": $cacheEngine = new CacheEngineFiles(); break; default: break; } } if ($cacheEngine == null) { throw new \Bitrix\Main\Config\ConfigurationException("Cache engine is not found"); } if (!$cacheEngine->isAvailable()) { throw new \Bitrix\Main\SystemException("Cache engine is not available"); } /* $v = \Bitrix\Main\Config\Configuration::getValue("cache"); if ($v != null && isset($v["type"])) { $cacheType = $v["type"]; if (is_array($cacheType)) { if (isset($cacheType["class_name"])) { if (!isset($cacheType["extension"]) || extension_loaded($cacheType["extension"])) { if (isset($cacheType["required_file"]) && ($requiredFile = \Bitrix\Main\Loader::getLocal($cacheType["required_file"]))) require_once($requiredFile); $className = $cacheType["class_name"]; if (class_exists($className)) $cacheEngine = new $className(); } } } else { switch ($cacheType) { case "memcache": if (extension_loaded('memcache')) $cacheEngine = new CacheEngineMemcache(); break; case "eaccelerator": if (extension_loaded('eaccelerator')) $cacheEngine = new CacheEngineEAccelerator(); break; case "apc": if (extension_loaded('apc')) $cacheEngine = new CacheEngineApc(); break; default: break; } } if (($cacheEngine != null) && !$cacheEngine->isAvailable()) $cacheEngine = null; } if ($cacheEngine == null) $cacheEngine = new CacheEngineFiles(); */ return new self($cacheEngine); }
public function getDefaultConnectionType() { $params = Config\Configuration::getValue('connections'); if (isset($params[static::DEFAULT_CONNECTION_NAME]) && !empty($params[static::DEFAULT_CONNECTION_NAME])) { $cn = $params[static::DEFAULT_CONNECTION_NAME]['className']; if ($cn === "\\Bitrix\\Main\\DB\\MysqlConnection" || $cn === "\\Bitrix\\Main\\DB\\MysqliConnection") { return 'MYSQL'; } elseif ($cn === "\\Bitrix\\Main\\DB\\OracleConnection") { return 'ORACLE'; } else { return 'MSSQL'; } } return strtoupper($GLOBALS["DBType"]); }
<?php /** * @link https://github.com/bitrix-expert/monolog-adapter * @copyright Copyright © 2015 Nik Samokhvalov * @license MIT */ use Bitrix\Main\Config\Configuration; use Cascade\Cascade; if (class_exists('\\Bitrix\\Main\\Config\\Configuration')) { $config = Configuration::getInstance()->get('monolog'); if (is_array($config) && !empty($config)) { Cascade::fileConfig($config); } }
/** * Return true if exception_handling debug = false * * @return bool * @since 14.0.0 */ protected function checkExceptionDebug() { $exceptionConfig = \Bitrix\Main\Config\Configuration::getValue('exception_handling'); return !(is_array($exceptionConfig) && isset($exceptionConfig['debug']) && $exceptionConfig['debug']); }
/** * Resets accelerator if any. */ public static function resetAccelerator() { if (defined("BX_NO_ACCELERATOR_RESET")) { return; } $fl = Config\Configuration::getValue("no_accelerator_reset"); if ($fl) { return; } if (function_exists("accelerator_reset")) { accelerator_reset(); } elseif (function_exists("wincache_refresh_if_changed")) { wincache_refresh_if_changed(); } }
/** * Return true if exception_handling debug = false * * @return bool * @since 14.0.0 */ protected function checkExceptionDebug() { $exceptionConfig = \Bitrix\Main\Config\Configuration::getValue('exception_handling'); if (is_array($exceptionConfig) && isset($exceptionConfig['debug']) && $exceptionConfig['debug']) { return self::STATUS_FAILED; } else { return self::STATUS_PASSED; } }
public static function createCacheEngine() { $cacheEngine = null; // Events can't be used here because events use cache $cacheType = "files"; $v = Config\Configuration::getValue("cache"); if ($v != null && isset($v["type"]) && !empty($v["type"])) { $cacheType = $v["type"]; } if (is_array($cacheType)) { if (isset($cacheType["class_name"])) { if (!isset($cacheType["extension"]) || extension_loaded($cacheType["extension"])) { if (isset($cacheType["required_file"]) && ($requiredFile = Main\Loader::getLocal($cacheType["required_file"])) !== false) { require_once $requiredFile; } if (isset($cacheType["required_remote_file"])) { require_once $cacheType["required_remote_file"]; } $className = $cacheType["class_name"]; if (class_exists($className)) { $cacheEngine = new $className(); } } } } else { switch ($cacheType) { case "memcache": if (extension_loaded('memcache')) { $cacheEngine = new CacheEngineMemcache(); } break; case "eaccelerator": if (extension_loaded('eaccelerator')) { $cacheEngine = new CacheEngineEAccelerator(); } break; case "apc": if (extension_loaded('apc')) { $cacheEngine = new CacheEngineApc(); } break; case "xcache": if (extension_loaded('xcache')) { $cacheEngine = new CacheEngineXCache(); } break; case "files": $cacheEngine = new CacheEngineFiles(); break; case "none": $cacheEngine = new CacheEngineNone(); break; default: break; } } if ($cacheEngine == null) { $cacheEngine = new CacheEngineNone(); trigger_error("Cache engine is not found", E_USER_WARNING); } if (!$cacheEngine->isAvailable()) { $cacheEngine = new CacheEngineNone(); trigger_error("Cache engine is not available", E_USER_WARNING); } return $cacheEngine; }
/** * Search connection parameters (type, host, db, login and password) by connection name * * @param string $name Connection name * @return array('type' => string, 'host' => string, 'db_name' => string, 'login' => string, 'password' => string, "init_command" => string, "options" => string)|null * @throws \Bitrix\Main\ArgumentTypeException * @throws \Bitrix\Main\ArgumentNullException */ private function searchConnectionParametersByName($name) { if (!is_string($name)) { throw new \Bitrix\Main\ArgumentTypeException("name", "string"); } if ($name === "") { throw new \Bitrix\Main\ArgumentNullException("name"); } if ($name === self::DEFAULT_CONNECTION) { $v = \Bitrix\Main\Config\Configuration::getValue(self::DEFAULT_CONNECTION_CONFIGURATION); if ($v != null) { return $v; } $DBType = ""; $DBHost = ""; $DBName = ""; $DBLogin = ""; $DBPassword = ""; include \Bitrix\Main\IO\Path::convertRelativeToAbsolute("/bitrix/php_interface/dbconn.php"); return array("type" => $DBType, "host" => $DBHost, "db_name" => $DBName, "login" => $DBLogin, "password" => $DBPassword); } /* TODO: реализовать */ return null; }
protected function getAuditors() { $wafConfig = \Bitrix\Main\Config\Configuration::getValue("waf"); if (is_array($wafConfig) && isset($wafConfig['auditors'])) return $wafConfig['auditors']; return $this->defaultAuditors; }
/** * Sets configs to .settings.php. * * @param InputInterface $input * @param OutputInterface $output * @param array $settings */ protected function configureSettings(InputInterface $input, OutputInterface $output, array $settings) { $configuration = Configuration::getInstance(); foreach ($settings as $name => $value) { $configuration->setValue($name, $value); } }