/** * @param IXmlExporter $exporter * @param int $status * @param string $contentType */ protected function xmlOutput(IXmlExporter $exporter, $status = 200, $contentType = 'application/xml') { $this->app->expires(0); $this->app->contentType($contentType); $response = $this->app->response(); $response->setStatus($status); $response->header('Content-Description', 'File Transfer'); if ($exporter->isFile()) { $response->header('Content-Disposition', 'attachment; filename=' . $exporter->getFileName()); } $response->body($exporter->buildXml()); }
/** * This methods will be called at application startup * @param $appInstance * @return void * @throws \Exception */ public static function addRouteDefinitions(Slim $appInstance) { $appInstance->map('/protected-storage/:inst/:id/:accessMethod/:path+', function ($inst, $id, $accessMethod, $path) use($appInstance) { if (!in_array($accessMethod, cProtectedStorage::$allowedAccessMethods, true)) { $appInstance->halt(400, 'Invalid request'); } $fileName = array_pop($path); $rel = ''; foreach ($path as $value) { $rel .= $value . '/'; } $rel .= $fileName; $user = null; if ($accessMethod === 'private') { try { $user = new MembersAuth(); $user->isUserLoggedIn(); } catch (LoginExceptions $e) { $appInstance->halt(401, 'Unauthorized'); } } $fullPath = $inst . '/' . $id . '/' . $accessMethod . '/' . $rel; $controller = new cProtectedStorage($inst, $id, $accessMethod, $rel); if ($controller->isCorrectPath($fullPath)) { $appInstance->etag(md5($fullPath)); $appInstance->expires('+1 week'); $headers = $controller->outputFile(); if (array_key_exists('download', $_REQUEST)) { $headers['Content-Type'] = 'application/octet-stream'; } foreach ($headers as $key => $value) { $appInstance->response->headers->set($key, $value); } } else { $appInstance->notFound(); } })->via('GET', 'POST'); }
public function cacheAndAccessHeader() { $this->_app->response->headers->set('Access-Control-Allow-Origin', '*'); $this->_app->expires(date('D, d M Y H:i:s O', time() + $this->_applicationConfig['cacheDuration'])); }