commercetools-sdk-php-v2  master
The platform, import-api and ml-api PHP sdks generated from our api reference.
FieldDefinitionBuilder.php
1 <?php
2 
3 declare(strict_types=1);
10 
18 use stdClass;
19 
23 final class FieldDefinitionBuilder implements Builder
24 {
29  private $type;
30 
35  private $name;
36 
41  private $label;
42 
47  private $required;
48 
53  private $inputHint;
54 
61  public function getType()
62  {
63  return $this->type instanceof FieldTypeBuilder ? $this->type->build() : $this->type;
64  }
65 
72  public function getName()
73  {
74  return $this->name;
75  }
76 
83  public function getLabel()
84  {
85  return $this->label instanceof LocalizedStringBuilder ? $this->label->build() : $this->label;
86  }
87 
94  public function getRequired()
95  {
96  return $this->required;
97  }
98 
105  public function getInputHint()
106  {
107  return $this->inputHint;
108  }
109 
114  public function withType(?FieldType $type)
115  {
116  $this->type = $type;
117 
118  return $this;
119  }
120 
125  public function withName(?string $name)
126  {
127  $this->name = $name;
128 
129  return $this;
130  }
131 
136  public function withLabel(?LocalizedString $label)
137  {
138  $this->label = $label;
139 
140  return $this;
141  }
142 
147  public function withRequired(?bool $required)
148  {
149  $this->required = $required;
150 
151  return $this;
152  }
153 
158  public function withInputHint(?string $inputHint)
159  {
160  $this->inputHint = $inputHint;
161 
162  return $this;
163  }
164 
169  public function withTypeBuilder(?FieldTypeBuilder $type)
170  {
171  $this->type = $type;
172 
173  return $this;
174  }
175 
180  public function withLabelBuilder(?LocalizedStringBuilder $label)
181  {
182  $this->label = $label;
183 
184  return $this;
185  }
186 
187  public function build(): FieldDefinition
188  {
189  return new FieldDefinitionModel(
190  $this->type instanceof FieldTypeBuilder ? $this->type->build() : $this->type,
191  $this->name,
192  $this->label instanceof LocalizedStringBuilder ? $this->label->build() : $this->label,
193  $this->required,
194  $this->inputHint
195  );
196  }
197 
198  public static function of(): FieldDefinitionBuilder
199  {
200  return new self();
201  }
202 }