public function createExceptionHandlerLog() { $exceptionHandling = Config\Configuration::getValue("exception_handling"); if ($exceptionHandling === null || !is_array($exceptionHandling) || !isset($exceptionHandling["log"]) || !is_array($exceptionHandling["log"])) { return null; } $options = $exceptionHandling["log"]; $log = null; if (isset($options["class_name"]) && !empty($options["class_name"])) { if (isset($options["extension"]) && !empty($options["extension"]) && !extension_loaded($options["extension"])) { return null; } if (isset($options["required_file"]) && !empty($options["required_file"]) && ($requiredFile = Loader::getLocal($options["required_file"])) !== false) { require_once $requiredFile; } $className = $options["class_name"]; if (!class_exists($className)) { return null; } $log = new $className(); } elseif (isset($options["settings"]) && is_array($options["settings"])) { $log = new Diag\FileExceptionHandlerLog(); } else { return null; } $log->initialize(isset($options["settings"]) && is_array($options["settings"]) ? $options["settings"] : array()); return $log; }
protected function sendToEventHandler(array $handler, Event $event) { try { $result = true; $event->addDebugInfo($handler); if (isset($handler["TO_MODULE_ID"]) && !empty($handler["TO_MODULE_ID"]) && $handler["TO_MODULE_ID"] != 'main') { $result = Loader::includeModule($handler["TO_MODULE_ID"]); } elseif (isset($handler["TO_PATH"]) && !empty($handler["TO_PATH"])) { $path = ltrim($handler["TO_PATH"], "/"); if (($path = Loader::getLocal($path)) !== false) { $result = (include_once $path); } } elseif (isset($handler["FULL_PATH"]) && !empty($handler["FULL_PATH"]) && IO\File::isFileExists($handler["FULL_PATH"])) { $result = (include_once $handler["FULL_PATH"]); } $event->addDebugInfo($result); if (isset($handler["TO_METHOD_ARG"]) && is_array($handler["TO_METHOD_ARG"]) && !empty($handler["TO_METHOD_ARG"])) { $args = $handler["TO_METHOD_ARG"]; } else { $args = array(); } if ($handler["VERSION"] > 1) { $args[] = $event; } else { $args = array_merge($args, array_values($event->getParameters())); } $callback = null; if (isset($handler["CALLBACK"])) { $callback = $handler["CALLBACK"]; } elseif (!empty($handler["TO_CLASS"]) && !empty($handler["TO_METHOD"]) && class_exists($handler["TO_CLASS"])) { $callback = array($handler["TO_CLASS"], $handler["TO_METHOD"]); } if ($callback != null) { $result = call_user_func_array($callback, $args); } if ($result != null && !$result instanceof EventResult) { $result = new EventResult(EventResult::UNDEFINED, $result, $handler["TO_MODULE_ID"]); } $event->addDebugInfo($result); if ($result != null) { $event->addResult($result); } } catch (\Exception $ex) { if ($event->isDebugOn()) { $event->addException($ex); } else { throw $ex; } } }
/** * Read messages from user defined lang file */ private static function loadCustomMessages($lang) { $customMess = array(); $documentRoot = Main\Application::getDocumentRoot(); if (($fname = Main\Loader::getLocal("php_interface/user_lang/" . $lang . "/lang.php", $documentRoot)) !== false) { $mess = self::includeFile($fname); // typical call is Loc::loadMessages(__FILE__) // __FILE__ can differ from path used in the user file foreach ($mess as $key => $val) { $customMess[str_replace("\\", "/", realpath($documentRoot . $key))] = $val; } } return $customMess; }
private static function loadTriggers($moduleId) { static $triggersCache = array(); if (isset($triggersCache[$moduleId])) { return; } if (preg_match("#[^a-zA-Z0-9._]#", $moduleId)) { throw new Main\ArgumentOutOfRangeException("moduleId"); } $triggersCache[$moduleId] = true; $path = Main\Loader::getLocal("modules/" . $moduleId . "/option_triggers.php"); if ($path === false) { return; } include $path; }
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; }