/** * Retrieve current page content. * * @param string $currentPageName * @param string &$header Generated header will be stored here * @return string Page content * @throws \Exception if page 404 is not configured (prevents redirection loop). */ public function getCurrentPageContent($currentPageName, &$header) { $this->handleEmptyPage($currentPageName); if ($this->maintenanceMode) { $currentPageName = $this->pageMaintenance; } if (!isset($this->pages[$currentPageName])) { // Prevent 404 redirection loop if 404 page is not configured if ($currentPageName == $this->pageNotFoundPage) { throw new \Exception("Page {$this->pageNotFoundPage} is not configured."); } $this->redirectTo404(); } $this->logger->logDebug("Loading page \"{$currentPageName}\""); /** @var Page */ $page = $this->pages[$currentPageName]; $headerArr = array(); $content = $page->getContent($this->tplEngine, $headerArr); $excludePageHead = $this->loadSpecificComponent !== false ? true : false; $header = $this->genHeaderString($headerArr, $page, $this->pagesUrl, $this->componentsUrl, $excludePageHead); return $content; }
/** * Sets PHP.INI values from config. */ private function setIniValues() { $displayErrorField = 'display_errors'; $errorReportingField = 'error_reporting'; $iniConfigFields = array($displayErrorField, $errorReportingField); $debugModeDependentFields = array($displayErrorField => "off", $errorReportingField => 0); $debugMode = $this->config->get("debug_mode"); foreach ($iniConfigFields as $field) { $value = $this->config->get($field); $this->logger->logDebug("Setting INI field \"{$field}\" to value: {$value}"); if (!$debugMode && array_key_exists($field, $debugModeDependentFields)) { $value = $debugModeDependentFields[$field]; } ini_set($field, $value); } }
/** * Loads logic component, by passed component name. * * @param string $logicToLoad Logic component name to load. * @param LogicComponent[] $logicComponentDependencies Logic components that current logic component depends on. * @return LogicComponent Loaded logic component object. * @throws Exception If loaded component does not extends the LogicComponent class. */ public function loadLogicComponent($logicToLoad, array $logicComponentDependencies) { $logicCompDir = $this->logicCompDir . $logicToLoad . '/'; $logicCompConfigDir = $logicCompDir . 'config/'; $this->logger->logDebug("Loading Logic component \"{$logicToLoad}\""); /** @noinspection PhpIncludeInspection */ require_once $logicCompDir . $logicToLoad . '.php'; $configObj = $this->loadComponentConfig($logicCompConfigDir, $logicToLoad); $className = $this->logicComponentNamespace . SFComponent::getClassName($logicToLoad); $logicComponentObj = new $className($logicToLoad, $configObj, $this->dbFactory, $logicComponentDependencies, $this->sf); if (!$logicComponentObj instanceof LogicComponent) { throw new Exception("Component \"{$logicToLoad}\" is not an instance of LogicComponent."); } $logicComponentObj->init(); $this->loadedLogicComponents[$logicToLoad] = $logicComponentObj; return $logicComponentObj; }
/** * Logs error to log file. * * @param string $exText Exception string. * @param string $exType Exception type. * @return string Since error text can be adjusted if the logger is not set, new text is returned so it can be used further. */ private static function saveToLogFile($exText, $exType) { $nl = ExceptionHandler::$newLine; $exTypeNameArr = explode("\\", $exType); $exTypeName = end($exTypeNameArr); if (ExceptionHandler::$logger === null) { $exText .= "{$nl}WARNING: Logger is not set and this is not written to the log file"; } else { switch (ExceptionHandler::$logLevel) { case LOG_LEVEL_ALL: ExceptionHandler::$logger->logError($exText); break; default: $exTypesToLog = explode(",", ExceptionHandler::$logLevel); if (in_array($exTypeName, $exTypesToLog)) { ExceptionHandler::$logger->logError($exText); } break; } } return $exText; }