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