/** * @desc Returns string representation of throwable * * @return array */ public function getStringRepresentation() { if (!is_array($this->throwableArray)) { $renderer = LegacyLogger::getHierarchy()->getRendererMap()->getByClassName(get_class($this->throwable)); // TODO: why this? if ($renderer instanceof LoggerRendererDefault) { $renderer = new LoggerRendererException(); } $this->throwableArray = explode("\n", $renderer->render($this->throwable)); } return $this->throwableArray; }
public function givenRequestToUriReturnsResult($uri, $result) { $parts = parse_url($uri); $key = $this->buildKey($parts['host'], $parts['path']); $this->resultsMap[$key] = $result; $that = $this; $this->httpApi->registerHandler("|^/tests/|i", function ($request, $response, $body) use($that) { $headers = $request->getHeaders(); $key = $that->buildKey($headers['Host'], $request->getPath()); if (isset($that->resultsMap[$key])) { $that->receivedRequests[$key] = $body; $responseBody = $that->resultsMap[$key]; $response->writeHead(200, array('Content-Length' => strlen($responseBody))); $response->end($responseBody); return; } LegacyLogger::log('ERROR', 'Tests', "Http-query '{$key}' not found"); $response->writeHead(404); $response->end(); }); }
public static function log_chat($channel, $sender, $message) { global $vars; if ($vars['show_aoml_markup'] == 0) { $message = preg_replace("/<font(.+)>/U", "", $message); $message = preg_replace("/<\\/font>/U", "", $message); $message = preg_replace("/<a(\\s+)href=\"(.+)\">/sU", "[link]", $message); $message = preg_replace("/<a(\\s+)href='(.+)'>/sU", "[link]", $message); $message = preg_replace("/<\\/a>/U", "[/link]", $message); } if ($channel == "Buddy") { $line = "[{$channel}] {$sender} {$message}"; } else { if ($sender == '-1') { $line = "[{$channel}] {$message}"; } else { $line = "[{$channel}] {$sender}: {$message}"; } } LegacyLogger::log('INFO', 'CHAT', $line); }
/** * @HandlesCommand("reloadinstance") * @Matches("/^reloadinstance (.+)$/i") */ public function reloadinstanceCommand($message, $channel, $sender, $sendto, $args) { $instanceName = $args[1]; $instance = Registry::getInstance($instanceName); if ($instance === null) { $msg = "Could not find instance <highlight>{$instanceName}<end>."; } else { try { $reflection = new ReflectionClass($instance); $syntaxResult = $this->checkSyntax($reflection->getFileName()); } catch (ReflectionException $e) { LegacyLogger::log("WARN", "Registry", "RUNKIT: Failed to reflect class, reason was: '" . $e->getMessage() . "'"); return; } if (preg_match("/^No syntax errors detected/", $syntaxResult)) { Registry::getInstance($instanceName, true); $msg = "Instance <highlight>{$instanceName}<end> has been reloaded."; } else { $msg = "Error reloading instance <highlight>{$instanceName}<end>: {$syntaxResult}"; } } $sendto->reply($msg); }
/** * eventCoreModuleAddlog * * @param mixed $args arguments supplied to triggerEvent * * @return void */ public static function eventCoreModuleAddlog($args) { LegacyLogger::getInstance()->addExtra($args[0], $args[1]); }
/** * Render message. * @return string */ public function getRenderedMessage() { if ($this->renderedMessage === null and $this->message !== null) { if (is_string($this->message)) { $this->renderedMessage = $this->message; } else { // $this->logger might be null or an instance of Logger or RootLogger // But in contrast to log4j, in log4php there is only have one LoggerHierarchy so there is // no need figure out which one is $this->logger part of. // TODO: LegacyLogger::getHierarchy() is marked @deprecated! $repository = LegacyLogger::getHierarchy(); $rendererMap = $repository->getRendererMap(); $this->renderedMessage = $rendererMap->findAndRender($this->message); } } return $this->renderedMessage; }
/** * Copies config.template.php to this config file if it doesn't exist yet. */ private function copyFromTemplateIfNeeded() { $templatePath = __DIR__ . '/../conf/config.template.php'; if (!file_exists($this->filePath)) { copy($templatePath, $this->filePath) or LegacyLogger::log('ERROR', 'StartUp', "could not create config file: {$this->filePath}"); } }
/** * @name: loadSQLFile * @description: Loads an sql file if there is an update * Will load the sql file with name $namexx.xx.xx.xx.sql if xx.xx.xx.xx is greater than settings[$name . "_sql_version"] * If there is an sql file with name $name.sql it would load that one every time */ public function loadSQLFile($module, $name, $forceUpdate = false) { $name = strtolower($name); // only letters, numbers, underscores are allowed if (!preg_match('/^[a-z0-9_]+$/i', $name)) { $msg = "Invalid SQL file name: '{$name}' for module: '{$module}'! Only numbers, letters, and underscores permitted!"; LegacyLogger::log('ERROR', 'SQL', $msg); return $msg; } $settingName = $name . "_db_version"; $dir = $this->util->verify_filename($module); if (empty($dir)) { $msg = "Could not find module '{$module}'."; LegacyLogger::log('ERROR', 'SQL', $msg); return $msg; } $d = dir($dir); if ($this->settingManager->exists($settingName)) { $currentVersion = $this->settingManager->get($settingName); } else { $currentVersion = false; } if ($currentVersion === false) { $currentVersion = 0; } $file = false; $maxFileVersion = 0; // 0 indicates no version if ($d) { while (false !== ($entry = $d->read())) { if (is_file("{$dir}/{$entry}") && preg_match("/^" . $name . "([0-9.]*)\\.sql\$/i", $entry, $arr)) { // If the file has no versioning in its filename, then we go off the modified timestamp if ($arr[1] == '') { $file = $entry; $maxFileVersion = filemtime("{$dir}/{$file}"); break; } if ($this->util->compare_version_numbers($arr[1], $maxFileVersion) >= 0) { $maxFileVersion = $arr[1]; $file = $entry; } } } } if ($file === false) { $msg = "No SQL file found with name '{$name}' in module '{$module}'!"; LegacyLogger::log('ERROR', 'SQL', $msg); return; } // make sure setting is verified so it doesn't get deleted $this->settingManager->add($module, $settingName, $settingName, 'noedit', 'text', 0); if ($forceUpdate || $this->util->compare_version_numbers($maxFileVersion, $currentVersion) > 0) { $handle = @fopen("{$dir}/{$file}", "r"); if ($handle) { try { while (($line = fgets($handle)) !== false) { $line = trim($line); // don't process comment lines or blank lines if ($line != '' && substr($line, 0, 1) != "#" && substr($line, 0, 2) != "--") { $this->exec($line); } } $this->settingManager->save($settingName, $maxFileVersion); if ($maxFileVersion != 0) { $msg = "Updated '{$name}' database from '{$currentVersion}' to '{$maxFileVersion}'"; LegacyLogger::log('DEBUG', 'SQL', $msg); } else { $msg = "Updated '{$name}' database"; LegacyLogger::log('DEBUG', 'SQL', $msg); } } catch (SQLException $e) { $msg = "Error loading sql file '{$file}': " . $e->getMessage(); LegacyLogger::log('ERROR', 'SQL', $msg); } } else { $msg = "Could not load SQL file: '{$dir}/{$file}'"; LegacyLogger::log('ERROR', 'SQL', $msg); } } else { $msg = "'{$name}' database already up to date! version: '{$currentVersion}'"; LegacyLogger::log('DEBUG', 'SQL', $msg); } return $msg; }
function paginate($input, $maxLength, $symbols) { $pageSize = 0; $currentPage = ''; $result = array(); $symbol = array_shift($symbols); $lines = explode($symbol, $input); foreach ($lines as $line) { if ($symbol == "\n") { $line .= "\n"; } $lineLength = strlen($line); if ($lineLength > $maxLength) { if ($pageSize != 0) { $result[] = $currentPage; $currentPage = ''; $pageSize = 0; } if (count($symbols) > 0) { $newResult = $this->paginate($line, $maxLength, $symbols); $result = array_merge($result, $newResult); } else { LegacyLogger::log('ERROR', 'Text', "Could not successfully page blob"); $result[] = $line; } } else { if ($pageSize + $lineLength < $maxLength) { $currentPage .= $line; $pageSize += $lineLength; } else { $result[] = $currentPage; $currentPage = $line; $pageSize = $lineLength; } } } if ($pageSize > 0) { $result[] = $currentPage; } return $result; }
function __get($value) { LegacyLogger::log('WARN', 'DB', "Tried to get value '{$value}' from row that doesn't exist"); }
function upgrade($db, $sql, $params = null) { try { $db->exec($sql); } catch (SQLException $e) { LegacyLogger::log("ERROR", 'Upgrade', $e->getMessage()); } }
public static function importChanges($instance) { try { $reflection = new ReflectionClass($instance); } catch (ReflectionException $e) { LegacyLogger::log("WARN", "Registry", "RUNKIT: Failed to reflect class, reason was: '" . $e->getMessage() . "'"); return; } LegacyLogger::log("DEBUG", "Registry", "Re-importing file '" . $reflection->getFileName() . "'"); runkit_import($reflection->getFileName(), RUNKIT_IMPORT_CLASSES | RUNKIT_IMPORT_FUNCTIONS | RUNKIT_IMPORT_OVERRIDE); }
public function get_logging_directory() { return LegacyLogger::get_logging_directory(); }
protected function getServerAndPort() { global $vars; // Choose server if ($vars['use_proxy'] === 1) { // For use with the AO chat proxy ONLY! $server = $vars['proxy_server']; $port = $vars['proxy_port']; } else { if ($vars["dimension"] == 1) { $server = "chat.d1.funcom.com"; $port = 7101; } else { if ($vars["dimension"] == 2) { $server = "chat.d2.funcom.com"; $port = 7102; } else { if ($vars["dimension"] == 4) { $server = "chat.dt.funcom.com"; $port = 7109; } else { LegacyLogger::log('ERROR', 'StartUp', "No valid server to connect with! Available dimensions are 1, 2 and 4."); sleep(10); die; } } } } return array($server, $port); }