56 lines
1.2 KiB
PHP
56 lines
1.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace HermannTelser\Watten\Utilities;
|
|
|
|
/***
|
|
*
|
|
* This file is part of the "mindshape Cookie Consent" Extension for TYPO3 CMS.
|
|
*
|
|
* For the full copyright and license information, please read the
|
|
* LICENSE.txt file that was distributed with this source code.
|
|
*
|
|
* (c) 2021 Daniel Dorndorf <dorndorf@mindshape.de>, mindshape GmbH
|
|
*
|
|
***/
|
|
|
|
/**
|
|
* @package HermannTelser\Watten\Utility
|
|
*/
|
|
class CookieUtility
|
|
{
|
|
public const DEFAULT_COOKIE_NAME = 'watten';
|
|
|
|
/**
|
|
|
|
* @param string $name
|
|
* @return array|null
|
|
*/
|
|
public static function getCookieValue(string $name = self::DEFAULT_COOKIE_NAME): ?array
|
|
{
|
|
if (false === self::hasCookie($name)) {
|
|
return null;
|
|
}
|
|
|
|
return json_decode($_COOKIE[$name], true);
|
|
}
|
|
|
|
/**
|
|
* @param string $named
|
|
* @return bool
|
|
*/
|
|
public static function hasCookie(string $name = self::DEFAULT_COOKIE_NAME): bool
|
|
{
|
|
return true === array_key_exists($name, $_COOKIE);
|
|
}
|
|
|
|
/**
|
|
* @param string $name
|
|
*/
|
|
public static function deleteCookie(string $name = self::DEFAULT_COOKIE_NAME): void
|
|
{
|
|
unset($_COOKIE[$name]);
|
|
}
|
|
}
|