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

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