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
  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.     public function offsetExists($offset)
  34.     {
  35.         return \array_key_exists($offset$this->data);
  36.     }
  37.     public function offsetGet($offset)
  38.     {
  39.         return $this->data[$offset] ?? null;
  40.     }
  41.     public function offsetSet($offset$value): void
  42.     {
  43.         $this->data[$offset] = $value;
  44.     }
  45.     public function offsetUnset($offset): void
  46.     {
  47.         unset($this->data[$offset]);
  48.     }
  49.     public function get(string $key)
  50.     {
  51.         return $this->offsetGet($key);
  52.     }
  53.     public function set($key$value)
  54.     {
  55.         return $this->data[$key] = $value;
  56.     }
  57.     public function assign(array $options)
  58.     {
  59.         $this->data array_replace_recursive($this->data$options);
  60.         if (\array_key_exists('id'$options)) {
  61.             $this->_uniqueIdentifier $options['id'];
  62.         }
  63.         return $this;
  64.     }
  65.     public function all()
  66.     {
  67.         return $this->data;
  68.     }
  69.     public function jsonSerialize(): array
  70.     {
  71.         $jsonArray parent::jsonSerialize();
  72.         // The key-values pairs from the property $data are now serialized in the JSON property "data". But the
  73.         // key-value pairs from data should appear in the serialization as they were properties of the ArrayEntity
  74.         // itself. Therefore the key-values moved one level up.
  75.         unset($jsonArray['data']);
  76.         $data $this->data;
  77.         $this->convertDateTimePropertiesToJsonStringRepresentation($data);
  78.         return array_merge($jsonArray$data);
  79.     }
  80. }