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

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