Skip to content

Commit

Permalink
Add CsrfTokenMiddleware support in CsrfViewInjection (#135)
Browse files Browse the repository at this point in the history
vjik authored Dec 16, 2024
1 parent 49a932a commit a3a209e
Showing 2 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@

## 7.2.1 under development

- no changes in this release.
- Enh #135: Add `CsrfTokenMiddleware` support in `CsrfViewInjection` (@vjik)

## 7.2.0 October 02, 2024

9 changes: 7 additions & 2 deletions src/CsrfViewInjection.php
Original file line number Diff line number Diff line change
@@ -7,9 +7,12 @@
use LogicException;
use Yiisoft\Csrf\CsrfMiddleware;
use Yiisoft\Csrf\CsrfTokenInterface;
use Yiisoft\Csrf\CsrfTokenMiddleware;

/**
* `CsrfViewInjection` injects the necessary data into the view to protect against a CSRF attack.
*
* @psalm-suppress DeprecatedClass `CsrfMiddleware` in `$middleware` property will be removed in next major version.
*/
final class CsrfViewInjection implements CommonParametersInjectionInterface, MetaTagsInjectionInterface
{
@@ -20,8 +23,10 @@ final class CsrfViewInjection implements CommonParametersInjectionInterface, Met
private string $metaAttributeName = self::DEFAULT_META_ATTRIBUTE_NAME;
private string $parameterName = self::DEFAULT_PARAMETER_NAME;

public function __construct(private CsrfTokenInterface $token, private CsrfMiddleware $middleware)
{
public function __construct(
private readonly CsrfTokenInterface $token,
private readonly CsrfTokenMiddleware|CsrfMiddleware $middleware,
) {
}

/**

0 comments on commit a3a209e

Please sign in to comment.