vendor/shopware/core/Framework/Struct/ArrayEntity.php line 8

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Shopware\Core\Framework\Struct;
  3. use Shopware\Core\Framework\DataAbstractionLayer\Entity;
  4. use Shopware\Core\Framework\DataAbstractionLayer\FieldVisibility;
  5. class ArrayEntity extends Entity implements \ArrayAccess
  6. {
  7.     /**
  8.      * @var array
  9.      */
  10.     protected $data;
  11.     /**
  12.      * @var string|null
  13.      */
  14.     protected $_entityName 'array-entity';
  15.     public function __construct(array $data = [])
  16.     {
  17.         $this->data $data;
  18.     }
  19.     /**
  20.      * @param string $name
  21.      *
  22.      * @return string|int|float|bool|array|object|null
  23.      */
  24.     public function __get($name)
  25.     {
  26.         if (FieldVisibility::$isInTwigRenderingContext) {
  27.             $this->checkIfPropertyAccessIsAllowed($name);
  28.         }
  29.         return $this->data[$name];
  30.     }
  31.     /**
  32.      * @param string $name
  33.      * @param string|int|float|bool|array|object|null $value
  34.      */
  35.     public function __set($name$value): void
  36.     {
  37.         $this->data[$name] = $value;
  38.     }
  39.     /**
  40.      * @param string $name
  41.      *
  42.      * @return bool
  43.      */
  44.     public function __isset($name)
  45.     {
  46.         if (FieldVisibility::$isInTwigRenderingContext && !$this->isPropertyVisible($name)) {
  47.             return false;
  48.         }
  49.         return isset($this->data[$name]);
  50.     }
  51.     public function has(string $property): bool
  52.     {
  53.         return \array_key_exists($property$this->data);
  54.     }
  55.     public function getUniqueIdentifier(): string
  56.     {
  57.         if (!$this->_uniqueIdentifier) {
  58.             return $this->data['id'];
  59.         }
  60.         return parent::getUniqueIdentifier();
  61.     }
  62.     public function getId(): string
  63.     {
  64.         return $this->data['id'];
  65.     }
  66.     /**
  67.      * @deprecated tag:v6.5.0 - return type will be changed to bool
  68.      */
  69.     #[\ReturnTypeWillChange]
  70.     public function offsetExists($offset)
  71.     {
  72.         if (FieldVisibility::$isInTwigRenderingContext && !$this->isPropertyVisible($offset)) {
  73.             return false;
  74.         }
  75.         return \array_key_exists($offset$this->data);
  76.     }
  77.     /**
  78.      * @deprecated tag:v6.5.0 - return type will be changed to mixed
  79.      */
  80.     #[\ReturnTypeWillChange]
  81.     public function offsetGet($offset)
  82.     {
  83.         if (FieldVisibility::$isInTwigRenderingContext) {
  84.             $this->checkIfPropertyAccessIsAllowed($offset);
  85.         }
  86.         return $this->data[$offset] ?? null;
  87.     }
  88.     public function offsetSet($offset$value): void
  89.     {
  90.         $this->data[$offset] = $value;
  91.     }
  92.     public function offsetUnset($offset): void
  93.     {
  94.         unset($this->data[$offset]);
  95.     }
  96.     public function get(string $key)
  97.     {
  98.         return $this->offsetGet($key);
  99.     }
  100.     public function set($key$value)
  101.     {
  102.         return $this->data[$key] = $value;
  103.     }
  104.     public function assign(array $options)
  105.     {
  106.         $this->data array_replace_recursive($this->data$options);
  107.         if (\array_key_exists('id'$options)) {
  108.             $this->_uniqueIdentifier $options['id'];
  109.         }
  110.         return $this;
  111.     }
  112.     public function all()
  113.     {
  114.         return $this->data;
  115.     }
  116.     /**
  117.      * @deprecated tag:v6.5.0 - return type will be changed to mixed
  118.      */
  119.     #[\ReturnTypeWillChange]
  120.     public function jsonSerialize(): array/* :mixed */
  121.     {
  122.         $jsonArray parent::jsonSerialize();
  123.         // The key-values pairs from the property $data are now serialized in the JSON property "data". But the
  124.         // key-value pairs from data should appear in the serialization as they were properties of the ArrayEntity
  125.         // itself. Therefore the key-values moved one level up.
  126.         unset($jsonArray['data'], $jsonArray['createdAt'], $jsonArray['updatedAt'], $jsonArray['versionId']);
  127.         $data $this->data;
  128.         $this->convertDateTimePropertiesToJsonStringRepresentation($data);
  129.         return array_merge($jsonArray$data);
  130.     }
  131. }