Beispiel #1
0
 public function send(ResponseEvent $event)
 {
     /** @var HttpResponseEx $response */
     $response = $event->getResponse();
     if (!headers_sent()) {
         foreach ($response->getHeaders() as $header) {
             header($header, false);
         }
     } else {
         echo '';
     }
     echo $response->getContent();
 }
Beispiel #2
0
 public function send(ResponseEvent $event)
 {
     /** @var HttpResponseEx $response */
     $response = $event->getResponse();
     if ($response->getStatusCode() === 401) {
         $user_id = $this->session->getLoggedInUserId();
         $reason = $user_id > 0 ? $this->lang->getText('Your account does not have the required authorization to view this page') : $this->lang->getText('You must be logged in to view this page');
         if ($event->isAjaxRequest()) {
             $response->setContent($reason);
         } else {
             $url = $this->response->getLoginRedirect($reason, true);
             $response->redirect($url, 302);
         }
     }
     if (!headers_sent()) {
         foreach ($response->getHeaders() as $header) {
             header($header, false);
         }
     }
     echo $response->getContent() ?? sprintf("Error code: %d", $response->getStatusCode());
 }
Beispiel #3
0
 public function minify(ResponseEvent $event)
 {
     if ($event->isSimpleHtmlResponse()) {
         /** @var HttpResponseEx $response */
         $response = $event->getResponse();
         try {
             if ($content = $response->getContent()) {
                 $settings = $this->cache->get('minify-settings', function () {
                     return $this->config->get(self::MINIFY_KEY);
                 }, 3600);
                 $version = $settings['version'] ?? 0 ?: 0.01;
                 if (!empty($settings['css']['files'])) {
                     $content = $this->compress('#<lin' . 'k (?:.+)?href="(/static/(?!cache/)[^"]+\\.css)"(?:.*)/?>#', $content, 'css', $version, $settings['css']['excludes'] ?? null);
                 }
                 if (!empty($settings['js']['files'])) {
                     $content = $this->compress('#<scrip' . 't (?:.+)?src="(/static/(?!cache/)[^"]+\\.js)"(?:.*)>\\s*</script>#', $content, 'js', $version, $settings['js']['excludes'] ?? null);
                 }
                 $response->setContent($content);
             }
         } catch (\Exception $e) {
             echo '';
         }
     }
 }