PluginProbe ʕ •ᴥ•ʔ
FAPI Member / 2.2.31
FAPI Member v2.2.31
2.2.33 2.2.32 trunk 1.9.47 2.1.18 2.2.24 2.2.25 2.2.26 2.2.28 2.2.29 2.2.30 2.2.31
fapi-member / libs / nette / http / src / Http / Context.php
fapi-member / libs / nette / http / src / Http Last commit date
Context.php 4 weeks ago FileUpload.php 4 weeks ago Helpers.php 4 weeks ago IRequest.php 4 weeks ago IResponse.php 4 weeks ago Request.php 4 weeks ago RequestFactory.php 4 weeks ago Response.php 4 weeks ago Session.php 4 weeks ago SessionSection.php 4 weeks ago Url.php 4 weeks ago UrlImmutable.php 4 weeks ago UrlScript.php 4 weeks ago UserStorage.php 4 weeks ago
Context.php
75 lines
1 <?php
2
3 /**
4 * This file is part of the Nette Framework (https://nette.org)
5 * Copyright (c) 2004 David Grudl (https://davidgrudl.com)
6 */
7 declare (strict_types=1);
8 namespace FapiMember\Library\Nette\Http;
9
10 use FapiMember\Library\Nette;
11 /**
12 * HTTP-specific tasks.
13 */
14 class Context
15 {
16 use Nette\SmartObject;
17 /** @var IRequest */
18 private $request;
19 /** @var IResponse */
20 private $response;
21 public function __construct(IRequest $request, IResponse $response)
22 {
23 $this->request = $request;
24 $this->response = $response;
25 }
26 /**
27 * Attempts to cache the sent entity by its last modification date.
28 * @param string|int|\DateTimeInterface $lastModified
29 */
30 public function isModified($lastModified = null, ?string $etag = null): bool
31 {
32 if ($lastModified) {
33 $this->response->setHeader('Last-Modified', Helpers::formatDate($lastModified));
34 }
35 if ($etag) {
36 $this->response->setHeader('ETag', '"' . addslashes($etag) . '"');
37 }
38 $ifNoneMatch = $this->request->getHeader('If-None-Match');
39 if ($ifNoneMatch === '*') {
40 $match = \true;
41 // match, check if-modified-since
42 } elseif ($ifNoneMatch !== null) {
43 $etag = $this->response->getHeader('ETag');
44 if ($etag === null || strpos(' ' . strtr($ifNoneMatch, ",\t", ' '), ' ' . $etag) === \false) {
45 return \true;
46 } else {
47 $match = \true;
48 // match, check if-modified-since
49 }
50 }
51 $ifModifiedSince = $this->request->getHeader('If-Modified-Since');
52 if ($ifModifiedSince !== null) {
53 $lastModified = $this->response->getHeader('Last-Modified');
54 if ($lastModified !== null && strtotime($lastModified) <= strtotime($ifModifiedSince)) {
55 $match = \true;
56 } else {
57 return \true;
58 }
59 }
60 if (empty($match)) {
61 return \true;
62 }
63 $this->response->setCode(IResponse::S304_NotModified);
64 return \false;
65 }
66 public function getRequest(): IRequest
67 {
68 return $this->request;
69 }
70 public function getResponse(): IResponse
71 {
72 return $this->response;
73 }
74 }
75