Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php
2
 
3
namespace Illuminate\Cookie;
4
 
5
class CookieValuePrefix
6
{
7
    /**
8
     * Create a new cookie value prefix for the given cookie name.
9
     *
10
     * @param  string  $cookieName
11
     * @param  string  $key
12
     * @return string
13
     */
14
    public static function create($cookieName, $key)
15
    {
16
        return hash_hmac('sha1', $cookieName.'v2', $key).'|';
17
    }
18
 
19
    /**
20
     * Remove the cookie value prefix.
21
     *
22
     * @param  string  $cookieValue
23
     * @return string
24
     */
25
    public static function remove($cookieValue)
26
    {
27
        return substr($cookieValue, 41);
28
    }
29
 
30
    /**
31
     * Validate a cookie value contains a valid prefix. If it does, return the cookie value with the prefix removed. Otherwise, return null.
32
     *
33
     * @param  string  $cookieName
34
     * @param  string  $cookieValue
35
     * @param  string  $key
36
     * @return string|null
37
     */
38
    public static function validate($cookieName, $cookieValue, $key)
39
    {
40
        $hasValidPrefix = str_starts_with($cookieValue, static::create($cookieName, $key));
41
 
42
        return $hasValidPrefix ? static::remove($cookieValue) : null;
43
    }
44
}