%PDF- %PDF-
Server IP : 37.220.80.31 / Your IP : 18.190.156.13 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/rest/lib/configuration/dataprovider/ |
Upload File : |
<?php namespace Bitrix\Rest\Configuration\DataProvider; use Bitrix\Main\Web\Json; use Bitrix\Rest\Configuration\Helper; use Bitrix\Main\ArgumentException; use Bitrix\Main\SystemException; /** * Class ProviderBase * @package Bitrix\Rest\Configuration\DataProvider */ abstract class ProviderBase { public const ERROR_DECODE_DATA = 'ERROR_DECODE_DATA'; public const ERROR_DATA_NOT_FOUND = 'ERROR_DATA_NOT_FOUND'; private $errorList = []; private $contextUser; private $context; /** * ProviderBase constructor. * * @param array $setting */ public function __construct(array $setting) { if ($setting['CONTEXT']) { $this->context = $setting['CONTEXT']; } if ($setting['CONTEXT_USER']) { $this->contextUser = $setting['CONTEXT_USER']; } } /** * Returns action context * * @return mixed|string */ protected function getContext() { return $this->context ?? Helper::getInstance()->getContextAction(); } /** * Return users action context * * @return mixed|string */ protected function getUserContext() { return $this->contextUser ?? Helper::getInstance()->getContextUser(''); } /** * Adds content as file to configuration folder. * * @param $code string name of file * @param $content string|array saving configuration data * @param $type mixed type of configuration data * * @return bool */ abstract public function addContent(string $code, $content, $type = false): bool; /** * Adds files to configurations files folder. * @param $files array files list * * @return array */ abstract public function addFiles(array $files): array; /** * Returns content from file * * @param string $path * @param int $step * * @return array|null */ abstract public function get(string $path, int $step): ?array; /** * Returns structured content for working * @param $path * * @return array */ public function getContent(string $path, int $step): array { $result = [ 'DATA' => null, '~DATA' => null, 'FILE_NAME' => null, 'SANITIZE' => false, 'COUNT' => 0, ]; try { $content = $this->get($path, $step); if (!is_null($content['DATA'])) { $result['~DATA'] = Json::decode($content['DATA']); if (!empty($result['~DATA'])) { $result['DATA'] = Helper::getInstance()->sanitize($result['~DATA'], $result['SANITIZE']); } } else { $result['ERROR_CODE'] = self::ERROR_DATA_NOT_FOUND; } if ($content['FILE_NAME']) { $result['FILE_NAME'] = preg_replace( '/(' . Helper::CONFIGURATION_FILE_EXTENSION . ')$/i', '', $content['FILE_NAME'] ); } if ((int)$content['COUNT'] > 0) { $result['COUNT'] = (int)$content['COUNT']; } } catch (ArgumentException $exception) { $result['ERROR_CODE'] = self::ERROR_DECODE_DATA; } catch (SystemException $exception) { $result['ERROR_CODE'] = self::ERROR_DATA_NOT_FOUND; } return $result; } /** * Makes string from content data. * * @param $content * @return false|string */ protected function packageContent($content): ?string { $result = null; if (is_array($content)) { try { $result = Json::encode($content); } catch (ArgumentException $e) { $result = null; $this->addError('ERROR_JSON_ENCODE', ''); } } elseif (is_string($content)) { $result = $content; } return $result; } /** * Adds error. * * @param $code * @param $message * * @return bool */ protected function addError($code, $message): bool { $this->errorList[$code] = $message; return true; } /** * Returns error list. * * @return array */ public function listError(): array { return $this->errorList; } /** * Resets errors. * * @return bool */ public function resetErrors(): bool { $this->errorList = []; return true; } }