/** * 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 responseStatus() { $this->_app->etag(md5($this->_app->response->getBody())); $this->_app->getLog()->debug('Response status: ' . $this->_app->response->getStatus()); }