Final Class Yiisoft\Yii\View\Renderer\CsrfViewInjection
| Inheritance | Yiisoft\Yii\View\Renderer\CsrfViewInjection |
|---|---|
| Implements | Yiisoft\Yii\View\Renderer\CommonParametersInjectionInterface, Yiisoft\Yii\View\Renderer\MetaTagsInjectionInterface |
CsrfViewInjection injects the necessary data into the view to protect against a CSRF attack.
Public Methods
| Method | Description | Defined By |
|---|---|---|
| __construct() | Yiisoft\Yii\View\Renderer\CsrfViewInjection | |
| getCommonParameters() | Yiisoft\Yii\View\Renderer\CsrfViewInjection | |
| getMetaTags() | Yiisoft\Yii\View\Renderer\CsrfViewInjection | |
| withMetaAttributeName() | Returns a new instance with the specified meta attribute name. | Yiisoft\Yii\View\Renderer\CsrfViewInjection |
| withParameterName() | Returns a new instance with the specified parameter name. | Yiisoft\Yii\View\Renderer\CsrfViewInjection |
Constants
| Constant | Value | Description | Defined By |
|---|---|---|---|
| DEFAULT_META_ATTRIBUTE_NAME | 'csrf' | Yiisoft\Yii\View\Renderer\CsrfViewInjection | |
| DEFAULT_PARAMETER_NAME | 'csrf' | Yiisoft\Yii\View\Renderer\CsrfViewInjection | |
| META_TAG_KEY | 'csrf' | Yiisoft\Yii\View\Renderer\CsrfViewInjection |
Method Details
| public mixed __construct ( \Yiisoft\Csrf\CsrfTokenInterface $token, \Yiisoft\Csrf\CsrfTokenMiddleware|\Yiisoft\Csrf\CsrfMiddleware $middleware ) | ||
| $token | \Yiisoft\Csrf\CsrfTokenInterface | |
| $middleware | \Yiisoft\Csrf\CsrfTokenMiddleware|\Yiisoft\Csrf\CsrfMiddleware | |
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;
}
Signup or Login in order to comment.