Skip to content

Commit

Permalink
Merge branch 'master' into parse_x_forwarded_host
Browse files Browse the repository at this point in the history
  • Loading branch information
dg authored Nov 4, 2024
2 parents 5311783 + 72a6d5a commit d703248
Show file tree
Hide file tree
Showing 65 changed files with 569 additions and 1,120 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/coding-style.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ jobs:
name: Nette Code Checker
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: shivammathur/setup-php@v2
with:
php-version: 7.2
php-version: 8.1
coverage: none

- run: composer create-project nette/code-checker temp/code-checker ^3 --no-progress
Expand All @@ -21,10 +21,10 @@ jobs:
name: Nette Coding Standard
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: shivammathur/setup-php@v2
with:
php-version: 8.0
php-version: 8.1
coverage: none

- run: composer create-project nette/coding-standard temp/coding-standard ^3 --no-progress
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ jobs:
name: PHPStan
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: shivammathur/setup-php@v2
with:
php-version: 7.4
php-version: 8.1
coverage: none

- run: composer install --no-progress --prefer-dist
Expand Down
14 changes: 7 additions & 7 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@ on: [push, pull_request]

env:
php-options: -C -d opcache.enable=0
php-extensions: fileinfo, intl
php-extensions: fileinfo, intl, gd

jobs:
tests:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macOS-latest]
php: ['7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3']
php: ['8.1', '8.2', '8.3', '8.4']
sapi: ['php', 'php-cgi']

fail-fast: false

name: PHP ${{ matrix.php }}/${{ matrix.sapi }} tests on ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
Expand All @@ -39,10 +39,10 @@ jobs:
name: Lowest Dependencies
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: shivammathur/setup-php@v2
with:
php-version: 7.2
php-version: 8.1
coverage: none
extensions: ${{ env.php-extensions }}

Expand All @@ -54,10 +54,10 @@ jobs:
name: Code Coverage
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: shivammathur/setup-php@v2
with:
php-version: 7.4
php-version: 8.1
coverage: none
extensions: ${{ env.php-extensions }}

Expand Down
11 changes: 7 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
}
],
"require": {
"php": "7.2 - 8.3",
"nette/utils": "^3.2.1 || ~4.0.0"
"php": "8.1 - 8.4",
"nette/utils": "^4.0.4"
},
"require-dev": {
"nette/di": "^3.0",
Expand All @@ -30,7 +30,10 @@
"nette/schema": "<1.2"
},
"suggest": {
"ext-fileinfo": "to detect type of uploaded files"
"ext-fileinfo": "to detect MIME type of uploaded files by Nette\\Http\\FileUpload",
"ext-gd": "to use image function in Nette\\Http\\FileUpload",
"ext-session": "to use Nette\\Http\\Session",
"ext-intl": "to support punycode by Nette\\Http\\Url"
},
"autoload": {
"classmap": ["src/"]
Expand All @@ -42,7 +45,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.3.
It requires PHP version 8.1 and supports PHP up to 8.4.


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


public function __construct(bool $cliMode = false)
{
$this->cliMode = $cliMode;
public function __construct(
private readonly bool $cliMode = false,
) {
}


Expand All @@ -48,7 +44,7 @@ public function getConfigSchema(): Nette\Schema\Schema
}


public function loadConfiguration()
public function loadConfiguration(): void
{
$builder = $this->getContainerBuilder();
$config = $this->config;
Expand Down Expand Up @@ -93,7 +89,7 @@ public function loadConfiguration()
}


private function sendHeaders()
private function sendHeaders(): void
{
$config = $this->config;
$headers = array_map('strval', $config->headers);
Expand All @@ -115,11 +111,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 +136,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
29 changes: 6 additions & 23 deletions src/Bridges/HttpDI/SessionExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,10 @@
*/
class SessionExtension extends Nette\DI\CompilerExtension
{
/** @var bool */
private $debugMode;

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


public function __construct(bool $debugMode = false, bool $cliMode = false)
{
$this->debugMode = $debugMode;
$this->cliMode = $cliMode;
public function __construct(
private readonly bool $debugMode = false,
private readonly bool $cliMode = false,
) {
}


Expand All @@ -41,13 +34,13 @@ 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');
}


public function loadConfiguration()
public function loadConfiguration(): void
{
$builder = $this->getContainerBuilder();
$config = $this->config;
Expand All @@ -67,16 +60,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
2 changes: 0 additions & 2 deletions src/Bridges/HttpTracy/SessionPanel.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
*/
class SessionPanel implements Tracy\IBarPanel
{
use Nette\SmartObject;

/**
* Renders tab.
*/
Expand Down
24 changes: 6 additions & 18 deletions src/Http/Context.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,35 +9,23 @@

namespace Nette\Http;

use Nette;


/**
* HTTP-specific tasks.
*/
class Context
{
use Nette\SmartObject;

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

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


public function __construct(IRequest $request, IResponse $response)
{
$this->request = $request;
$this->response = $response;
public function __construct(
private readonly IRequest $request,
private readonly 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 +42,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
Loading

0 comments on commit d703248

Please sign in to comment.