vendor/shopware/core/Framework/Struct/ArrayStruct.php line 5

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