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

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Shopware\Core\Framework\Struct;
  3. use Shopware\Core\Framework\DataAbstractionLayer\Entity;
  4. class ArrayEntity extends Entity implements \ArrayAccess
  5. {
  6.     /**
  7.      * @var array
  8.      */
  9.     protected $data;
  10.     /**
  11.      * @var string|null
  12.      */
  13.     protected $_entityName 'array-entity';
  14.     public function __construct(array $data = [])
  15.     {
  16.         $this->data $data;
  17.     }
  18.     public function has(string $property): bool
  19.     {
  20.         return \array_key_exists($property$this->data);
  21.     }
  22.     public function getUniqueIdentifier(): string
  23.     {
  24.         if (!$this->_uniqueIdentifier) {
  25.             return $this->data['id'];
  26.         }
  27.         return parent::getUniqueIdentifier();
  28.     }
  29.     public function getId(): string
  30.     {
  31.         return $this->data['id'];
  32.     }
  33.     /**
  34.      * @deprecated tag:v6.5.0 - return type will be changed to bool
  35.      */
  36.     #[\ReturnTypeWillChange]
  37.     public function offsetExists($offset)
  38.     {
  39.         return \array_key_exists($offset$this->data);
  40.     }
  41.     /**
  42.      * @deprecated tag:v6.5.0 - return type will be changed to mixed
  43.      */
  44.     #[\ReturnTypeWillChange]
  45.     public function offsetGet($offset)
  46.     {
  47.         return $this->data[$offset] ?? null;
  48.     }
  49.     public function offsetSet($offset$value): void
  50.     {
  51.         $this->data[$offset] = $value;
  52.     }
  53.     public function offsetUnset($offset): void
  54.     {
  55.         unset($this->data[$offset]);
  56.     }
  57.     public function get(string $key)
  58.     {
  59.         return $this->offsetGet($key);
  60.     }
  61.     public function set($key$value)
  62.     {
  63.         return $this->data[$key] = $value;
  64.     }
  65.     public function assign(array $options)
  66.     {
  67.         $this->data array_replace_recursive($this->data$options);
  68.         if (\array_key_exists('id'$options)) {
  69.             $this->_uniqueIdentifier $options['id'];
  70.         }
  71.         return $this;
  72.     }
  73.     public function all()
  74.     {
  75.         return $this->data;
  76.     }
  77.     /**
  78.      * @deprecated tag:v6.5.0 - return type will be changed to mixed
  79.      */
  80.     #[\ReturnTypeWillChange]
  81.     public function jsonSerialize(): array/* :mixed */
  82.     {
  83.         $jsonArray parent::jsonSerialize();
  84.         // The key-values pairs from the property $data are now serialized in the JSON property "data". But the
  85.         // key-value pairs from data should appear in the serialization as they were properties of the ArrayEntity
  86.         // itself. Therefore the key-values moved one level up.
  87.         unset($jsonArray['data']);
  88.         $data $this->data;
  89.         $this->convertDateTimePropertiesToJsonStringRepresentation($data);
  90.         return array_merge($jsonArray$data);
  91.     }
  92. }