本文整理汇总了PHP中Symfony\Component\HttpFoundation\StreamedResponse::isNotModified方法的典型用法代码示例。如果您正苦于以下问题:PHP StreamedResponse::isNotModified方法的具体用法?PHP StreamedResponse::isNotModified怎么用?PHP StreamedResponse::isNotModified使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\HttpFoundation\StreamedResponse
的用法示例。
在下文中一共展示了StreamedResponse::isNotModified方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setHeaders
/**
* Set the streamed response headers.
* @param StreamedResponse $response The response object.
* @return StreamedResponse
*/
public function setHeaders(StreamedResponse $response)
{
$response->headers->set('Content-Type', $this->cache->getMimetype($this->path));
$response->headers->set('Content-Length', $this->cache->getSize($this->path));
$response->setPublic();
$response->setMaxAge(31536000);
$response->setExpires(date_create()->modify('+1 years'));
$response->setLastModified(date_create()->setTimestamp($this->cache->getTimestamp($this->path)));
$response->isNotModified($this->request);
return $response;
}
示例2: thread
protected function thread($num = 0, $options = [])
{
$this->profiler->log('Controller Chan::thread Start');
$num = str_replace('S', '', $num);
try {
$board = Board::forge($this->getContext())->getThread($num)->setRadix($this->radix)->setOptions($options);
// get the current status of the thread
$thread_status = $board->getThreadStatus();
$last_modified = $thread_status['last_modified'];
$this->setLastModified($last_modified);
if (!$this->response->isNotModified($this->request)) {
$this->response = new StreamedResponse();
$this->setLastModified($last_modified);
// execute in case there's more exceptions to handle
$thread = $board->getComments();
// get the latest doc_id and latest timestamp for realtime stuff
$latest_doc_id = $board->getHighest('doc_id')->comment->doc_id;
$latest_timestamp = $board->getHighest('timestamp')->comment->timestamp;
$this->builder->getProps()->addTitle(_i('Thread') . ' #' . $num);
$this->param_manager->setParams(['thread_id' => $num, 'is_thread' => true, 'disable_image_upload' => $thread_status['disable_image_upload'], 'thread_dead' => $thread_status['dead'], 'latest_doc_id' => $latest_doc_id, 'latest_timestamp' => $latest_timestamp, 'thread_op_data' => $thread[$num]['op']]);
$this->builder->createPartial('body', 'board')->getParamManager()->setParams(['board' => $board->getComments()]);
$backend_vars = $this->param_manager->getParam('backend_vars');
$backend_vars['thread_id'] = $num;
$backend_vars['latest_timestamp'] = $latest_timestamp;
$backend_vars['latest_doc_id'] = $latest_doc_id;
$backend_vars['board_shortname'] = $this->radix->shortname;
if (isset($options['last_limit']) && $options['last_limit']) {
$this->param_manager->setParam('controller_method', 'last/' . $options['last_limit']);
$backend_vars['last_limit'] = $options['last_limit'];
}
$this->param_manager->setParam('backend_vars', $backend_vars);
if (!$thread_status['closed']) {
$this->builder->createPartial('tools_reply_box', 'tools_reply_box');
}
$this->profiler->logMem('Controller Chan $this', $this);
$this->profiler->log('Controller Chan::thread End');
$this->response->setCallback(function () {
$this->builder->stream();
});
}
} catch (\Foolz\Foolfuuka\Model\BoardThreadNotFoundException $e) {
$this->profiler->log('Controller Chan::thread End Prematurely');
return $this->error($e->getMessage(), 404);
} catch (\Foolz\Foolfuuka\Model\BoardException $e) {
$this->profiler->log('Controller Chan::thread End Prematurely');
return $this->error($e->getMessage());
}
return $this->response;
}
示例3: manifestAction
/**
* @param string $build
* @param Request $request
* @return Response
*/
public function manifestAction($build, Request $request)
{
$this->closeSession($request);
try {
$manifest = $this->application->getManifest($build);
} catch (FileNotFoundException $e) {
throw new NotFoundHttpException('Not Found', $e);
}
$response = new StreamedResponse(function () {
echo '';
});
$response->setETag($manifest->computeETag())->setLastModified(\DateTime::createFromFormat('U', $manifest->getMTime()))->setPublic();
if ($response->isNotModified($request)) {
return $response;
}
$response->setCallback(function () use($manifest) {
echo $manifest->getContent();
});
$response->headers->set('Content-Type', 'application/json');
return $response;
}
示例4: execute
public function execute(Request $request, WorkingFolder $workingFolder, EventDispatcher $dispatcher, Config $config)
{
$fileName = (string) $request->query->get('fileName');
$thumbnailFileName = (string) $request->query->get('thumbnail');
if (!File::isValidName($fileName, $config->get('disallowUnsafeCharacters'))) {
throw new InvalidRequestException(sprintf('Invalid file name: %s', $fileName));
}
$cacheLifetime = (int) $request->query->get('cache');
if (!$workingFolder->containsFile($fileName)) {
throw new FileNotFoundException();
}
if ($thumbnailFileName) {
if (!File::isValidName($thumbnailFileName, $config->get('disallowUnsafeCharacters'))) {
throw new InvalidRequestException(sprintf('Invalid resized image file name: %s', $fileName));
}
if (!$workingFolder->getResourceType()->isAllowedExtension(pathinfo($thumbnailFileName, PATHINFO_EXTENSION))) {
throw new InvalidExtensionException();
}
$resizedImageRespository = $this->app->getResizedImageRepository();
$file = $resizedImageRespository->getExistingResizedImage($workingFolder->getResourceType(), $workingFolder->getClientCurrentFolder(), $fileName, $thumbnailFileName);
$dataStream = $file->readStream();
} else {
$file = new DownloadedFile($fileName, $this->app);
$file->isValid();
$dataStream = $workingFolder->readStream($file->getFilename());
}
$proxyDownload = new ProxyDownloadEvent($this->app, $file);
$dispatcher->dispatch(CKFinderEvent::PROXY_DOWNLOAD, $proxyDownload);
if ($proxyDownload->isPropagationStopped()) {
throw new AccessDeniedException();
}
$response = new StreamedResponse();
$response->headers->set('Content-Type', $file->getMimeType());
$response->headers->set('Content-Length', $file->getSize());
$response->headers->set('Content-Disposition', 'inline; filename="' . $fileName . '"');
if ($cacheLifetime > 0) {
Utils::removeSessionCacheHeaders();
$response->setPublic();
$response->setEtag(dechex($file->getTimestamp()) . "-" . dechex($file->getSize()));
$lastModificationDate = new \DateTime();
$lastModificationDate->setTimestamp($file->getTimestamp());
$response->setLastModified($lastModificationDate);
if ($response->isNotModified($request)) {
return $response;
}
$response->setMaxAge($cacheLifetime);
$expireTime = new \DateTime();
$expireTime->modify('+' . $cacheLifetime . 'seconds');
$response->setExpires($expireTime);
}
$chunkSize = 1024 * 100;
$response->setCallback(function () use($dataStream, $chunkSize) {
if ($dataStream === false) {
return false;
}
while (!feof($dataStream)) {
echo fread($dataStream, $chunkSize);
flush();
@set_time_limit(8);
}
return true;
});
return $response;
}