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 / Helpers.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
Helpers.php
53 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 use FapiMember\Library\Nette\Utils\DateTime;
12 /**
13 * Rendering helpers for HTTP.
14 */
15 final class Helpers
16 {
17 use Nette\StaticClass;
18 /** @internal */
19 public const StrictCookieName = '_nss';
20 /** @deprecated */
21 public const STRICT_COOKIE_NAME = self::StrictCookieName;
22 /**
23 * Returns HTTP valid date format.
24 * @param string|int|\DateTimeInterface $time
25 */
26 public static function formatDate($time): string
27 {
28 $time = DateTime::from($time)->setTimezone(new \DateTimeZone('GMT'));
29 return $time->format('D, d M Y H:i:s \G\M\T');
30 }
31 /**
32 * Is IP address in CIDR block?
33 */
34 public static function ipMatch(string $ip, string $mask): bool
35 {
36 [$mask, $size] = explode('/', $mask . '/');
37 $tmp = function (int $n): string {
38 return sprintf('%032b', $n);
39 };
40 $ip = implode('', array_map($tmp, unpack('N*', inet_pton($ip))));
41 $mask = implode('', array_map($tmp, unpack('N*', inet_pton($mask))));
42 $max = strlen($ip);
43 if (!$max || $max !== strlen($mask) || (int) $size < 0 || (int) $size > $max) {
44 return \false;
45 }
46 return strncmp($ip, $mask, ($size === '') ? $max : (int) $size) === 0;
47 }
48 public static function initCookie(IRequest $request, IResponse $response)
49 {
50 $response->setCookie(self::StrictCookieName, '1', 0, '/', null, null, \true, IResponse::SameSiteStrict);
51 }
52 }
53