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

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