vendor/shopware/core/Framework/DataAbstractionLayer/Field/ListField.php line 57

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Shopware\Core\Framework\DataAbstractionLayer\Field;
  3. use Shopware\Core\Framework\DataAbstractionLayer\FieldSerializer\ListFieldSerializer;
  4. use Shopware\Core\Framework\Feature;
  5. /**
  6.  * Stores a JSON formatted value list. This can be typed using the third constructor parameter.
  7.  *
  8.  * Definition example:
  9.  *
  10.  *      // allow every type
  11.  *      new ListField('product_ids', 'productIds');
  12.  *
  13.  *      // allow int types only
  14.  *      new ListField('product_ids', 'productIds', IntField::class);
  15.  *
  16.  * Output in database:
  17.  *
  18.  *      // mixed type value
  19.  *      ['this is a string', 'another string', true, 15]
  20.  *
  21.  *      // single type values
  22.  *      [12,55,192,22]
  23.  */
  24. class ListField extends JsonField
  25. {
  26.     /**
  27.      * @var string|null
  28.      */
  29.     private $fieldType;
  30.     /**
  31.      * @deprecated tag:v6.5.0 Property strict will be removed
  32.      *
  33.      * @var bool
  34.      */
  35.     private $strict false;
  36.     public function __construct(string $storageNamestring $propertyName, ?string $fieldType null)
  37.     {
  38.         parent::__construct($storageName$propertyName);
  39.         $this->fieldType $fieldType;
  40.     }
  41.     public function getFieldType(): ?string
  42.     {
  43.         return $this->fieldType;
  44.     }
  45.     /**
  46.      * Strict `ListField` does not support keys and will strip them on decode. Use `JsonField` instead.
  47.      *
  48.      * @deprecated tag:v6.5.0 - will be removed
  49.      */
  50.     public function isStrict(): bool
  51.     {
  52.         if (!$this->strict) {
  53.             Feature::triggerDeprecationOrThrow(
  54.                 'v6.5.0.0',
  55.                 Feature::deprecatedMethodMessage(__CLASS____METHOD__'v6.5.0.0''JsonField')
  56.             );
  57.         }
  58.         return $this->strict;
  59.     }
  60.     /**
  61.      * Enable strict mode which forces the decode to return non-associative array. (json_encode will encode it as an array instead of an object)
  62.      *
  63.      * @deprecated tag:v6.5.0 - will be removed
  64.      */
  65.     public function setStrict(bool $strict): ListField
  66.     {
  67.         if (!$strict) {
  68.             Feature::triggerDeprecationOrThrow(
  69.                 'v6.5.0.0',
  70.                 Feature::deprecatedMethodMessage(__CLASS____METHOD__'v6.5.0.0''JsonField')
  71.             );
  72.         }
  73.         $this->strict $strict;
  74.         return $this;
  75.     }
  76.     protected function getSerializerClass(): string
  77.     {
  78.         return ListFieldSerializer::class;
  79.     }
  80. }