scripts = new Scripts($template); } /** * Remove recursions and iterator objects from an object * * @param mixed $object Object to clean * @param mixed[] $stack Stack used to keep track of recursion, need not be passed for the first time * * @return mixed Reference passed object */ private static function removeRecursion(mixed &$object, array $stack = []): mixed { if ((is_object($object) || is_array($object)) && $object) { if ($object instanceof Traversable) { $object = '***ITERATOR***'; } elseif (! in_array($object, $stack, true)) { $stack[] = $object; // @phpstan-ignore-next-line foreach ($object as &$subObject) { self::removeRecursion($subObject, $stack); } } else { $object = '***RECURSION***'; } } return $object; } /** * Renders the debug messages */ public function getDebugMessage(): string { $retval = '\'false\''; if ($this->config->config->debug->sql && empty($_REQUEST['no_debug']) && ! empty($_SESSION['debug'])) { // Remove recursions and iterators from $_SESSION['debug'] self::removeRecursion($_SESSION['debug']); $retval = (string) json_encode($_SESSION['debug']); $_SESSION['debug'] = []; return json_last_error() !== 0 ? '\'false\'' : $retval; } $_SESSION['debug'] = []; return $retval; } /** * Returns the url of the current page */ public function getSelfUrl(): string { $params = []; $params['route'] = Routing::$route; if (Current::$database !== '') { $params['db'] = Current::$database; } if (Current::$table !== '') { $params['table'] = Current::$table; } $params['server'] = Current::$server; if (isset($_REQUEST['single_table'])) { $params['single_table'] = $_REQUEST['single_table']; } return basename(Core::getEnv('SCRIPT_NAME')) . Url::getCommonRaw($params); } /** * Renders the link to open a new page */ public function getErrorMessages(): string { $retval = ''; $errorHandler = ErrorHandler::getInstance(); if ($errorHandler->hasDisplayErrors()) { $retval .= $errorHandler->getDispErrors(); } /** * Report php errors */ $errorHandler->reportErrors(); return $retval; } /** * Turn on minimal display mode */ public function setMinimal(): void { $this->isMinimal = true; } /** * Returns the Scripts object * * @return Scripts object */ public function getScripts(): Scripts { return $this->scripts; } /** @return mixed[] */ public function getDisplay(): array { if (! $this->isMinimal) { if (Core::getEnv('SCRIPT_NAME') !== '') { $url = $this->getSelfUrl(); } $this->scripts->addCode('window.Console.debugSqlInfo = ' . $this->getDebugMessage() . ';'); $errorMessages = $this->getErrorMessages(); $scripts = $this->scripts->getDisplay(); if ($this->config->config->debug->demo) { $git = new Git(true, ROOT_PATH); $gitRevisionInfo = $git->getGitRevisionInfo(); } $footer = self::renderFooter(); } return [ 'is_minimal' => $this->isMinimal, 'self_url' => $url ?? null, 'error_messages' => $errorMessages ?? '', 'scripts' => $scripts ?? '', 'is_demo' => $this->config->config->debug->demo, 'git_revision_info' => $gitRevisionInfo ?? [], 'footer' => $footer ?? '', ]; } /** * Renders user configured footer */ public static function renderFooter(): string { return Generator::renderCustom(CUSTOM_FOOTER_FILE, 'pma_footer'); } }