Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/coding-style.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
- uses: actions/checkout@v3
- uses: shivammathur/setup-php@v2
with:
php-version: 7.2
php-version: 8.0
coverage: none

- run: composer create-project nette/code-checker temp/code-checker ^3 --no-progress
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- uses: actions/checkout@v3
- uses: shivammathur/setup-php@v2
with:
php-version: 7.4
php-version: 8.0
coverage: none

- run: composer install --no-progress --prefer-dist
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macOS-latest]
php: ['7.2', '7.3', '7.4', '8.0', '8.1', '8.2']
php: ['8.0', '8.1', '8.2']
sapi: ['php', 'php-cgi']

fail-fast: false
Expand Down Expand Up @@ -42,7 +42,7 @@ jobs:
- uses: actions/checkout@v3
- uses: shivammathur/setup-php@v2
with:
php-version: 7.2
php-version: 8.0
coverage: none
extensions: ${{ env.php-extensions }}

Expand All @@ -57,7 +57,7 @@ jobs:
- uses: actions/checkout@v3
- uses: shivammathur/setup-php@v2
with:
php-version: 7.4
php-version: 8.0
coverage: none
extensions: ${{ env.php-extensions }}

Expand Down
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
}
],
"require": {
"php": ">=7.2 <8.3",
"nette/utils": "^3.2.1 || ~4.0.0"
"php": ">=8.0 <8.3",
"nette/utils": "^3.2 || ^4.0"
},
"require-dev": {
"nette/di": "^3.0",
"nette/di": "^3.1 || ^4.0",
"nette/tester": "^2.4",
"nette/security": "^3.0",
"nette/security": "^4.0",
"tracy/tracy": "^2.8",
"phpstan/phpstan": "^1.0"
},
Expand All @@ -42,7 +42,7 @@
},
"extra": {
"branch-alias": {
"dev-master": "3.2-dev"
"dev-master": "4.0-dev"
}
}
}
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Installation
composer require nette/http
```

It requires PHP version 7.2 and supports PHP up to 8.2.
It requires PHP version 8.0 and supports PHP up to 8.2.


HTTP Request
Expand Down
9 changes: 4 additions & 5 deletions src/Bridges/HttpDI/HttpExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
*/
class HttpExtension extends Nette\DI\CompilerExtension
{
/** @var bool */
private $cliMode;
private bool $cliMode;


public function __construct(bool $cliMode = false)
Expand Down Expand Up @@ -115,11 +114,11 @@ private function sendHeaders()
}

$value = self::buildPolicy($config->$key);
if (strpos($value, "'nonce'")) {
if (str_contains($value, "'nonce'")) {
$this->initialization->addBody('$cspNonce = base64_encode(random_bytes(16));');
$value = Nette\DI\ContainerBuilder::literal(
'str_replace(?, ? . $cspNonce, ?)',
["'nonce", "'nonce-", $value]
["'nonce", "'nonce-", $value],
);
}

Expand All @@ -140,7 +139,7 @@ private function sendHeaders()
if (!$config->disableNetteCookie) {
$this->initialization->addBody(
'Nette\Http\Helpers::initCookie($this->getService(?), $response);',
[$this->prefix('request')]
[$this->prefix('request')],
);
}
}
Expand Down
19 changes: 3 additions & 16 deletions src/Bridges/HttpDI/SessionExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,8 @@
*/
class SessionExtension extends Nette\DI\CompilerExtension
{
/** @var bool */
private $debugMode;

/** @var bool */
private $cliMode;
private bool $debugMode;
private bool $cliMode;


public function __construct(bool $debugMode = false, bool $cliMode = false)
Expand All @@ -41,7 +38,7 @@ public function getConfigSchema(): Nette\Schema\Schema
'expiration' => Expect::string()->dynamic(),
'handler' => Expect::string()->dynamic(),
'readAndClose' => Expect::bool(),
'cookieSamesite' => Expect::anyOf(IResponse::SameSiteLax, IResponse::SameSiteStrict, IResponse::SameSiteNone, true)
'cookieSamesite' => Expect::anyOf(IResponse::SameSiteLax, IResponse::SameSiteStrict, IResponse::SameSiteNone)
->firstIsDefault(),
])->otherItems('mixed');
}
Expand All @@ -67,16 +64,6 @@ public function loadConfiguration()
$config->cookieDomain = $builder::literal('$this->getByType(Nette\Http\IRequest::class)->getUrl()->getDomain(2)');
}

if (isset($config->cookieSecure)) {
trigger_error("The item 'session\u{a0}›\u{a0}cookieSecure' is deprecated, use 'http\u{a0}›\u{a0}cookieSecure' (it has default value 'auto').", E_USER_DEPRECATED);
unset($config->cookieSecure);
}

if ($config->cookieSamesite === true) {
trigger_error("In 'session\u{a0}›\u{a0}cookieSamesite' replace true with 'Lax'.", E_USER_DEPRECATED);
$config->cookieSamesite = IResponse::SameSiteLax;
}

$this->compiler->addExportedType(Nette\Http\IRequest::class);

if ($this->debugMode && $config->debugger) {
Expand Down
12 changes: 4 additions & 8 deletions src/Http/Context.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,8 @@ class Context
{
use Nette\SmartObject;

/** @var IRequest */
private $request;

/** @var IResponse */
private $response;
private IRequest $request;
private IResponse $response;


public function __construct(IRequest $request, IResponse $response)
Expand All @@ -35,9 +32,8 @@ public function __construct(IRequest $request, IResponse $response)

/**
* Attempts to cache the sent entity by its last modification date.
* @param string|int|\DateTimeInterface $lastModified
*/
public function isModified($lastModified = null, ?string $etag = null): bool
public function isModified(string|int|\DateTimeInterface|null $lastModified = null, ?string $etag = null): bool
{
if ($lastModified) {
$this->response->setHeader('Last-Modified', Helpers::formatDate($lastModified));
Expand All @@ -54,7 +50,7 @@ public function isModified($lastModified = null, ?string $etag = null): bool
} elseif ($ifNoneMatch !== null) {
$etag = $this->response->getHeader('ETag');

if ($etag === null || strpos(' ' . strtr($ifNoneMatch, ",\t", ' '), ' ' . $etag) === false) {
if ($etag === null || !str_contains(' ' . strtr($ifNoneMatch, ",\t", ' '), ' ' . $etag)) {
return true;

} else {
Expand Down
31 changes: 10 additions & 21 deletions src/Http/FileUpload.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,28 +29,17 @@ final class FileUpload
{
use Nette\SmartObject;

public const ImageMimeTypes = ['image/gif', 'image/png', 'image/jpeg', 'image/webp'];
public const ImageMimeTypes = ['image/gif', 'image/png', 'image/jpeg', 'image/webp', 'image/avif'];

/** @deprecated use FileUpload::ImageMimeTypes */
public const IMAGE_MIME_TYPES = self::ImageMimeTypes;

/** @var string */
private $name;

/** @var string|null */
private $fullPath;

/** @var string|false|null */
private $type;

/** @var int */
private $size;

/** @var string */
private $tmpName;

/** @var int */
private $error;
private string $name;
private string|null $fullPath;
private string|false|null $type = null;
private int $size;
private string $tmpName;
private int $error;


public function __construct(?array $value)
Expand All @@ -75,6 +64,7 @@ public function __construct(?array $value)
*/
public function getName(): string
{
trigger_error(__METHOD__ . '() is deprecated, use getUntrustedName()', E_USER_DEPRECATED);
return $this->name;
}

Expand Down Expand Up @@ -193,9 +183,8 @@ public function hasFile(): bool

/**
* Moves an uploaded file to a new location. If the destination file already exists, it will be overwritten.
* @return static
*/
public function move(string $dest)
public function move(string $dest): static
{
$dir = dirname($dest);
Nette\Utils\FileSystem::createDir($dir);
Expand All @@ -205,7 +194,7 @@ public function move(string $dest)
[$this->tmpName, $dest],
function (string $message) use ($dest): void {
throw new Nette\InvalidStateException("Unable to move uploaded file '$this->tmpName' to '$dest'. $message");
}
},
);
@chmod($dest, 0666); // @ - possible low permission to chmod
$this->tmpName = $dest;
Expand Down
10 changes: 3 additions & 7 deletions src/Http/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,11 @@ final class Helpers
/** @internal */
public const StrictCookieName = '_nss';

/** @deprecated */
public const STRICT_COOKIE_NAME = self::StrictCookieName;


/**
* Returns HTTP valid date format.
* @param string|int|\DateTimeInterface $time
*/
public static function formatDate($time): string
public static function formatDate(string|int|\DateTimeInterface $time): string
{
$time = DateTime::from($time)->setTimezone(new \DateTimeZone('GMT'));
return $time->format('D, d M Y H:i:s \G\M\T');
Expand All @@ -44,7 +40,7 @@ public static function formatDate($time): string
public static function ipMatch(string $ip, string $mask): bool
{
[$mask, $size] = explode('/', $mask . '/');
$tmp = function (int $n): string { return sprintf('%032b', $n); };
$tmp = fn(int $n): string => sprintf('%032b', $n);
$ip = implode('', array_map($tmp, unpack('N*', inet_pton($ip))));
$mask = implode('', array_map($tmp, unpack('N*', inet_pton($mask))));
$max = strlen($ip);
Expand All @@ -58,6 +54,6 @@ public static function ipMatch(string $ip, string $mask): bool

public static function initCookie(IRequest $request, IResponse $response)
{
$response->setCookie(self::StrictCookieName, '1', 0, '/', null, null, true, IResponse::SameSiteStrict);
$response->setCookie(self::StrictCookieName, '1', 0, '/', sameSite: IResponse::SameSiteStrict);
}
}
12 changes: 4 additions & 8 deletions src/Http/IRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,22 +58,19 @@ function getUrl(): UrlScript;
/**
* Returns variable provided to the script via URL query ($_GET).
* If no key is passed, returns the entire array.
* @return mixed
*/
function getQuery(?string $key = null);
function getQuery(?string $key = null): mixed;

/**
* Returns variable provided to the script via POST method ($_POST).
* If no key is passed, returns the entire array.
* @return mixed
*/
function getPost(?string $key = null);
function getPost(?string $key = null): mixed;

/**
* Returns uploaded file.
* @return FileUpload|array|null
*/
function getFile(string $key);
function getFile(string $key): ?FileUpload;

/**
* Returns uploaded files.
Expand All @@ -82,9 +79,8 @@ function getFiles(): array;

/**
* Returns variable provided to the script via HTTP cookies.
* @return mixed
*/
function getCookie(string $key);
function getCookie(string $key): mixed;

/**
* Returns variables provided to the script via HTTP cookies.
Expand Down
Loading