%PDF- %PDF-
Server IP : 37.220.80.31 / Your IP : 3.129.26.204 Web Server : Apache/2.4.52 (Ubuntu) System : Linux 3051455-guretool.twc1.net 5.15.0-107-generic #117-Ubuntu SMP Fri Apr 26 12:26:49 UTC 2024 x86_64 User : www-root ( 1010) PHP Version : 7.4.33 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority, MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /var/www/www-root/data/www/dev.artlot24.ru/bitrix/modules/itserw.wishlist/lib/ |
Upload File : |
<?php namespace Itserw\Wishlist; use \Bitrix\Main\Application; use \Bitrix\Main\Config\Option; use \Bitrix\Main\Web\Cookie; use \Bitrix\Main\HttpRequest; /** * Class DataStorageCookie * @package Itserw\Wishlist */ class DataStorageCookie implements DataStorageInterface { use InfoSerializeArrayTrait; /** * @var string */ private $cookieId = 'field_cookie_name'; /** * @var string */ private $cookieName = 'ITSERW_WISHLIST'; /** * @var array */ private static $instances = array(); /** * @return mixed */ private function getOptionCookieName() { return Option::get(Favorites::moduleId, $this->cookieId, $this->cookieName, SITE_ID); } /** * DataStorageCookie constructor. */ protected function __construct() { } /** * @return mixed */ public static function getInstance() { $cls = static::class; if (!isset(static::$instances[$cls])) { static::$instances[$cls] = new static; } return static::$instances[$cls]; } /** * @param array $value */ public function addStorage(array $value) { $application = Application::getInstance(); $context = $application->getContext(); $cookie = new Cookie($this->getOptionCookieName(), serialize($value), time() + 60 * 60 * 24 * 60); $cookie->setDomain($context->getServer()->getServerName()); $cookie->setHttpOnly(false); $context->getResponse()->addCookie($cookie); } /** * */ public function deleteStorage() { $application = Application::getInstance(); $context = $application->getContext(); $cookie = new Cookie($this->getOptionCookieName(), '', time() - 3600); $cookie->setDomain($context->getServer()->getServerName()); $cookie->setHttpOnly(false); $context->getResponse()->addCookie($cookie); } /** * @return bool */ public function isStorage() { return Application::getInstance()->getContext()->getRequest()->getCookie($this->getOptionCookieName()) ? true : false; } /** * @param array $values */ public function addStorageValue(array $values) { foreach (GetModuleEvents(Favorites::moduleId, "OnBeforeCookieFavoritesValueAdd", true) as $arEvent) { if (ExecuteModuleEventEx($arEvent, array(&$values)) === false) return false; } $data = $this->getStorageValue(); $keys = $this->isStorageValue($values); if ($keys) { foreach ($keys as $key) { unset($data[$key]); } } $results = array_merge($data, $values); $this->addStorage($results); foreach (GetModuleEvents(Favorites::moduleId, "OnAfterCookieFavoritesValueAdd", true) as $arEvent) { ExecuteModuleEventEx($arEvent, array($results)); return true; } } /** * @param array $values * @return bool */ public function deleteStorageValue(array $values) { foreach (GetModuleEvents(Favorites::moduleId, "OnBeforeCookieFavoritesValueDelete", true) as $arEvent) { if (ExecuteModuleEventEx($arEvent, array(&$values)) === false) return false; } $data = $this->getStorageValue(); $keys = $this->isStorageValue($values); if ($keys) { foreach ($keys as $key) { unset($data[$key]); } $this->addStorage($data); foreach (GetModuleEvents(Favorites::moduleId, "OnAfterCookieFavoritesValueDelete", true) as $arEvent) { ExecuteModuleEventEx($arEvent, array($data)); return true; } return true; } return false; } /** * @return mixed */ public function getStorageValue() { $value = Application::getInstance()->getContext()->getRequest()->getCookie($this->getOptionCookieName()); $result = array(); if ($value && $this->isSerialized($value)) { $result = unserialize($value); }else if ($value && !$this->isSerialized($value)) { $result = explode(',', $value); } return $result; } /** * @param array $values * @return array */ public function isStorageValue(array $values) { $data = $this->getStorageValue(); $result = array(); foreach ($values as $key => $value) { if (in_array($value, $data)) { $result[] = array_search($value, $data); } } return $result; } }