Final Class Yiisoft\Yii\View\Renderer\CsrfViewInjection
| Inheritance | Yiisoft\ |
|---|---|
| Implements | Yiisoft\ |
CsrfViewInjection injects the necessary data into the view to protect against a CSRF attack.
Public Methods
| Method | Description | Defined By |
|---|---|---|
| __construct() | Yiisoft\ |
|
| getCommonParameters() | Yiisoft\ |
|
| getMetaTags() | Yiisoft\ |
|
| withMetaAttributeName() | Returns a new instance with the specified meta attribute name. | Yiisoft\ |
| withParameterName() | Returns a new instance with the specified parameter name. | Yiisoft\ |
Constants
| Constant | Value | Description | Defined By |
|---|---|---|---|
| DEFAULT_META_ATTRIBUTE_NAME | 'csrf' | Yiisoft\ |
|
| DEFAULT_PARAMETER_NAME | 'csrf' | Yiisoft\ |
|
| META_TAG_KEY | 'csrf' | Yiisoft\ |
Method Details
| public mixed __construct ( \ | ||
| $token | \ |
|
| $middleware | \ |
|
public function __construct(
private readonly CsrfTokenInterface $token,
private readonly CsrfTokenMiddleware|CsrfMiddleware $middleware,
) {}
| public array getCommonParameters ( ) | ||
| throws | LogicException |
when CSRF token is not defined |
|---|---|---|
public function getCommonParameters(): array
{
$csrf = new Csrf(
$this->token->getValue(),
$this->middleware->getParameterName(),
$this->middleware->getHeaderName(),
);
return [$this->parameterName => $csrf];
}
| public array getMetaTags ( ) | ||
| throws | LogicException |
when CSRF token is not defined |
|---|---|---|
public function getMetaTags(): array
{
return [
self::META_TAG_KEY => [
'name' => $this->metaAttributeName,
'content' => $this->token->getValue(),
],
];
}
Returns a new instance with the specified meta attribute name.
| public self withMetaAttributeName ( string $metaAttributeName ) | ||
| $metaAttributeName | string |
The meta attribute name. |
public function withMetaAttributeName(string $metaAttributeName): self
{
$new = clone $this;
$new->metaAttributeName = $metaAttributeName;
return $new;
}
Returns a new instance with the specified parameter name.
| public self withParameterName ( string $parameterName ) | ||
| $parameterName | string |
The parameter name. |
public function withParameterName(string $parameterName): self
{
$new = clone $this;
$new->parameterName = $parameterName;
return $new;
}
User Contributed Notes
Leave a comment
Join the conversation to share a note.