custom/plugins/GbmedForm/src/Framework/Struct/GbmedFormStruct.php line 22

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. /**
  3.  * gb media
  4.  * All Rights Reserved.
  5.  *
  6.  * Unauthorized copying of this file, via any medium is strictly prohibited.
  7.  * The content of this file is proprietary and confidential.
  8.  *
  9.  * @category       Shopware
  10.  * @package        Shopware_Plugins
  11.  * @subpackage     GbmedForm
  12.  * @copyright      Copyright (c) 2020, gb media
  13.  * @license        proprietary
  14.  * @author         Giuseppe Bottino
  15.  * @link           http://www.gb-media.biz
  16.  */
  17. namespace Gbmed\Form\Framework\Struct;
  18. use Shopware\Core\Framework\Struct\Struct;
  19. class GbmedFormStruct extends Struct implements \ArrayAccess
  20. {
  21.     /**
  22.      * @var array
  23.      */
  24.     protected $data;
  25.     public function __construct(array $data = [])
  26.     {
  27.         $this->data $data;
  28.     }
  29.     public function has(string $property): bool
  30.     {
  31.         return \array_key_exists($property$this->data);
  32.     }
  33.     public function offsetExists($offset)
  34.     {
  35.         return \array_key_exists($offset$this->data);
  36.     }
  37.     public function offsetGet($offset)
  38.     {
  39.         return $this->data[$offset] ?? null;
  40.     }
  41.     public function offsetSet($offset$value): void
  42.     {
  43.         $this->data[$offset] = $value;
  44.     }
  45.     public function offsetUnset($offset): void
  46.     {
  47.         unset($this->data[$offset]);
  48.     }
  49.     public function get(string $key)
  50.     {
  51.         return $this->offsetGet($key);
  52.     }
  53.     public function set($key$value)
  54.     {
  55.         return $this->data[$key] = $value;
  56.     }
  57.     public function assign(array $options)
  58.     {
  59.         $this->data array_replace_recursive($this->data$options);
  60.         return $this;
  61.     }
  62.     public function all()
  63.     {
  64.         return $this->data;
  65.     }
  66.     public function jsonSerialize(): array
  67.     {
  68.         $data parent::jsonSerialize();
  69.         unset($data['data']);
  70.         foreach ($this->data as $property => $value) {
  71.             if ($value instanceof \DateTimeInterface) {
  72.                 $value $value->format(\DateTime::ATOM);
  73.             }
  74.             $data[$property] = $value;
  75.         }
  76.         return $data;
  77.     }
  78.     public function getApiAlias(): string
  79.     {
  80.         return 'array_struct';
  81.     }
  82. }