/** * Returns whether the content of the given internet media type is binary. * * Returns TRUE in case the content of the given internet media type is * binary or the given internet media type is not known by this library. * Otherwise returns FALSE. * * @param \Ableron\Lib\Net\InternetMediaType $internetMediaType The internet media type to check * @return bool */ public static function hasBinaryContent(InternetMediaType $internetMediaType) { if (!self::isKnown($internetMediaType)) { Application::getLogManager()->warning(sprintf('Unable to check whether internet media type "%s" has binary content: Unknown internet media type', $internetMediaType->getBaseType())); return true; } return self::$internetMediaTypes[$internetMediaType->getPrimaryType()][$internetMediaType->getSubType()]['isBinary']; }
/** * Returns the value of the context setting with the given name. * * Returns NULL in case the requested setting does not exist. * * @param string $settingName Name of the setting to return the value of * @return mixed */ public function getSetting(string $settingName) { if (!array_key_exists($settingName, $this->contextSettings)) { Application::getLogManager()->warning(sprintf('Unable to read context setting "%s": Setting does not exist!', $settingName)); return null; } return $this->contextSettings[$settingName]; }
/** * Returns the text with the given key for the currently set locale. * * TODO: Use MessageFormatter correctly (use object to get access to getErrorMessage() * TODO: Formatting messages may return FALSE on errors * * @param string $textKey Key of the text to return * @param array $parameters List of parameters to pass to the message formatter * @return string */ public function translate($textKey, $parameters = array()) { $query = Application::getPersistenceManager()->getEntityManager()->createQuery('SELECT t.text FROM Core:TranslationEntity t WHERE t.textKey = ?1 AND t.locale = ?2'); $query->setParameter(1, $textKey); $query->setParameter(2, $this->getLocale()); try { return MessageFormatter::formatMessage($this->getLocale()->getLocaleCode(), $query->getSingleScalarResult(), $parameters); } catch (NoResultException $e) { Application::getLogManager()->warning(sprintf('Unable to translate text key "%s": No translation found', $textKey)); return ''; } }
/** * Forwards a method call. * * @param string $settingType Type of the setting to forward the method call for * @param string $methodName Name of the method to call * @param array $methodParameters Parameters to pass along the method call * @param mixed $fallbackReturnValue Return value in case the method call could not be forwarded * @return mixed */ private static function forwardMethodCall(string $settingType, string $methodName, array $methodParameters, $fallbackReturnValue) { // get setting class $settingClass = self::getSettingImplementationClass($settingType); // check whether setting class exists if (!class_exists($settingClass)) { Application::getLogManager()->warning(sprintf('Unable to forward method call for setting type "%s": Unknown setting type', $settingType)); return $fallbackReturnValue; } // forward the method call return forward_static_call_array(array($settingClass, $methodName), $methodParameters); }
/** * Sends the response header. * * @return void */ public function sendResponseHeader() { // check whether response has already been sent if ($this->isResponseSent()) { Application::getLogManager()->error('Unable to send response header: Response header already sent'); } // check whether content has already been sent if (headers_sent($file, $line)) { Application::getLogManager()->error(sprintf('Unable to send response header: Response header already sent in %s on line %d', $file, $line)); } // add cache headers to the response $this->addCacheHeaders($this->getResponse()); // set status line header($this->getResponse()->getStatusLine(), true, $this->getResponse()->getStatusCode()); // set header fields /** @var \Ableron\Lib\Stdlib\Implementations\GenericHeaderField $headerField */ foreach ($this->getResponse()->getHeaderFields() as $headerField) { header($headerField->toString()); } // set cookies $this->sendCookies(); // mark response as sent $this->responseSent = true; }
/** * @see \Ableron\Core\Controller\ControllerInterface::processRequest() */ public function processRequest(HttpRequest $request) { // set request to process $this->request = $request; // process request try { $this->init(); $this->checkAccessPermissions(); $this->run(); } catch (RedirectRequiredException $e) { Application::getResponseHandler()->sendRedirect($e->getRedirectUri()); } catch (AccessDeniedException $e) { Application::getRequestHandler()->isFrontendRequest() ? new FrontendAccessDeniedPage($this->request) : new BackendAccessDeniedPage($this->request); } catch (SystemException $e) { // log exception Application::getLogManager()->logException('Unable to process request', $e); // stop script execution Application::exitWithInternalServerError(); } }