Ouzo\Csrf\CsrfProtector::protect PHP Метод

protect() публичный статический Метод

public static protect ( Controller $controller )
$controller Ouzo\Controller
    public static function protect(Controller $controller)
    {
        $controller->before[] = function () {
            if (CsrfProtector::isMethodProtected(Uri::getRequestType())) {
                CsrfProtector::validate();
            }
            return true;
        };
        $controller->after[] = function () use($controller) {
            $controller->setCookie(array('name' => 'csrftoken', 'value' => CsrfProtector::getCsrfToken(), 'expire' => 0, 'path' => '/'));
            return true;
        };
    }

Usage Example

Пример #1
0
 public function init()
 {
     CsrfProtector::protect($this);
 }