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

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Shopware\Core\Framework\Struct;
  3. use Shopware\Core\Framework\DataAbstractionLayer\Entity;
  4. use Shopware\Core\Framework\DataAbstractionLayer\FieldVisibility;
  5. use Shopware\Core\Framework\Feature;
  6. class ArrayEntity extends Entity implements \ArrayAccess
  7. {
  8.     /**
  9.      * @var array
  10.      */
  11.     protected $data;
  12.     /**
  13.      * @var string|null
  14.      */
  15.     protected $_entityName 'array-entity';
  16.     public function __construct(array $data = [])
  17.     {
  18.         $this->data $data;
  19.     }
  20.     /**
  21.      * @param string $name
  22.      *
  23.      * @return string|int|float|bool|array|object|null
  24.      */
  25.     public function __get($name)
  26.     {
  27.         if (FieldVisibility::$isInTwigRenderingContext) {
  28.             $this->checkIfPropertyAccessIsAllowed($name);
  29.         }
  30.         return $this->data[$name];
  31.     }
  32.     /**
  33.      * @param string $name
  34.      * @param string|int|float|bool|array|object|null $value
  35.      */
  36.     public function __set($name$value): void
  37.     {
  38.         $this->data[$name] = $value;
  39.     }
  40.     /**
  41.      * @param string $name
  42.      *
  43.      * @return bool
  44.      */
  45.     public function __isset($name)
  46.     {
  47.         if (FieldVisibility::$isInTwigRenderingContext && !$this->isPropertyVisible($name)) {
  48.             return false;
  49.         }
  50.         return isset($this->data[$name]);
  51.     }
  52.     public function has(string $property): bool
  53.     {
  54.         return \array_key_exists($property$this->data);
  55.     }
  56.     public function getUniqueIdentifier(): string
  57.     {
  58.         if (!$this->_uniqueIdentifier) {
  59.             return $this->data['id'];
  60.         }
  61.         return parent::getUniqueIdentifier();
  62.     }
  63.     public function getId(): string
  64.     {
  65.         return $this->data['id'];
  66.     }
  67.     /**
  68.      * @deprecated tag:v6.5.0 - reason:return-type-change - return type will be changed to bool
  69.      */
  70.     #[\ReturnTypeWillChange]
  71.     public function offsetExists($offset)
  72.     {
  73.         if (FieldVisibility::$isInTwigRenderingContext && !$this->isPropertyVisible($offset)) {
  74.             return false;
  75.         }
  76.         return \array_key_exists($offset$this->data);
  77.     }
  78.     /**
  79.      * @deprecated tag:v6.5.0 - reason:return-type-change - return type will be changed to mixed
  80.      */
  81.     #[\ReturnTypeWillChange]
  82.     public function offsetGet($offset)
  83.     {
  84.         if (FieldVisibility::$isInTwigRenderingContext) {
  85.             $this->checkIfPropertyAccessIsAllowed($offset);
  86.         }
  87.         return $this->data[$offset] ?? null;
  88.     }
  89.     public function offsetSet($offset$value): void
  90.     {
  91.         $this->data[$offset] = $value;
  92.     }
  93.     public function offsetUnset($offset): void
  94.     {
  95.         unset($this->data[$offset]);
  96.     }
  97.     public function get(string $key)
  98.     {
  99.         return $this->offsetGet($key);
  100.     }
  101.     public function set($key$value)
  102.     {
  103.         return $this->data[$key] = $value;
  104.     }
  105.     public function assign(array $options)
  106.     {
  107.         $this->data array_replace_recursive($this->data$options);
  108.         if (\array_key_exists('id'$options)) {
  109.             $this->_uniqueIdentifier $options['id'];
  110.         }
  111.         return $this;
  112.     }
  113.     public function all()
  114.     {
  115.         return $this->data;
  116.     }
  117.     public function getVars(): array
  118.     {
  119.         $vars parent::getVars();
  120.         if (Feature::isActive('v6.5.0.0')) {
  121.             unset($vars['data']);
  122.         }
  123.         return array_merge($vars$this->data);
  124.     }
  125.     /**
  126.      * @deprecated tag:v6.5.0 - reason:return-type-change - return type will be changed to mixed
  127.      */
  128.     #[\ReturnTypeWillChange]
  129.     public function jsonSerialize(): array/* :mixed */
  130.     {
  131.         $jsonArray parent::jsonSerialize();
  132.         // The key-values pairs from the property $data are now serialized in the JSON property "data". But the
  133.         // key-value pairs from data should appear in the serialization as they were properties of the ArrayEntity
  134.         // itself. Therefore the key-values moved one level up.
  135.         unset($jsonArray['data'], $jsonArray['createdAt'], $jsonArray['updatedAt'], $jsonArray['versionId']);
  136.         $data $this->data;
  137.         $this->convertDateTimePropertiesToJsonStringRepresentation($data);
  138.         return array_merge($jsonArray$data);
  139.     }
  140. }