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

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