0 follower

Final Class Yiisoft\Yii\View\Renderer\CsrfViewInjection

InheritanceYiisoft\Yii\View\Renderer\CsrfViewInjection
ImplementsYiisoft\Yii\View\Renderer\CommonParametersInjectionInterface, Yiisoft\Yii\View\Renderer\MetaTagsInjectionInterface

CsrfViewInjection injects the necessary data into the view to protect against a CSRF attack.

Constants

Hide inherited 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

Hide inherited methods

__construct() public method

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,
) {
}

            
getCommonParameters() public method

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];
}

            
getMetaTags() public method

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(),
        ],
    ];
}

            
withMetaAttributeName() public method

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;
}

            
withParameterName() public method

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;
}