Beispiel #1
0
 /**
  * @param \Zend\Stdlib\ResponseInterface $r
  * @param \Zend_Controller_Response_Abstract $response
  */
 public function renderIntoResponse(Response $r, \Zend_Controller_Response_Abstract $response)
 {
     // render ZF1 response into ZF2 response
     if ($response->isException() && $response->renderExceptions()) {
         $exceptions = '';
         foreach ($response->getException() as $e) {
             $exceptions .= $e . "\n";
         }
         $body = $exceptions;
     } else {
         $body = $response->getBody();
     }
     $r->setContent($body);
     if ($r instanceof HttpResponse) {
         $r->setStatusCode($response->getHttpResponseCode());
         $r->setHeaders($this->getHeadersFromResponse($response));
         $type = $r->getHeaders()->get('Content-Type');
         if (!$type) {
             $r->getHeaders()->addHeaderLine('Content-Type', 'text/html');
         }
     }
 }
Beispiel #2
0
 /**
  * Execute the request
  *
  * @param RequestInterface $request
  * @param ResponseInterface $response (Default: null)
  * @return \Zend\Http\PhpEnvironment\Response
  */
 public function dispatch(RequestInterface $request, ResponseInterface $response = null)
 {
     // the config hash
     $config = $this->getServiceLocator()->get('Config');
     $config = $config['TpMinify'];
     // some important stuff
     $config['serveOptions']['quiet'] = true;
     // the time correction
     Minify::$uploaderHoursBehind = $config['uploaderHoursBehind'];
     // the cache engine
     Minify::setCache($config['cachePath'] ?: '', $config['cacheFileLocking']);
     // doc root corrections
     if ($config['documentRoot']) {
         $_SERVER['DOCUMENT_ROOT'] = $config['documentRoot'];
         Minify::$isDocRootSet = true;
     }
     // check for URI versioning
     if (preg_match('~&\\d~', $request->getUriString())) {
         $config['serveOptions']['maxAge'] = 31536000;
     }
     // minify result as array of information
     $result = Minify::serve('MinApp', $config['serveOptions']);
     // some corrections
     if (isset($result['headers']['_responseCode'])) {
         unset($result['headers']['_responseCode']);
     }
     // the headers set
     $headers = new Headers();
     $headers->addHeaders($result['headers']);
     // final output
     return $response->setHeaders($headers)->setStatusCode($result['statusCode'])->setContent($result['content']);
 }