Actions
3 years ago
Concerns
3 years ago
Conditions
4 years ago
Contracts
3 years ago
Exceptions
3 years ago
Facades
4 years ago
Checkbox.php
4 years ago
Date.php
4 years ago
Element.php
3 years ago
Email.php
4 years ago
Factory.php
4 years ago
Field.php
3 years ago
File.php
3 years ago
Form.php
3 years ago
Group.php
3 years ago
Hidden.php
4 years ago
Html.php
4 years ago
Option.php
3 years ago
Phone.php
4 years ago
Radio.php
4 years ago
Section.php
3 years ago
Select.php
4 years ago
Text.php
4 years ago
Textarea.php
4 years ago
Types.php
4 years ago
Url.php
4 years ago
Field.php
71 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Give\Framework\FieldsAPI; |
| 4 | |
| 5 | use Give\Framework\FieldsAPI\Contracts\Node; |
| 6 | use Give\Framework\FieldsAPI\Exceptions\EmptyNameException; |
| 7 | use Give\Vendors\StellarWP\Validation\Concerns\HasValidationRules; |
| 8 | |
| 9 | /** |
| 10 | * @since 2.17.0 allow fields to be macroable |
| 11 | * @since 2.12.0 |
| 12 | * @since 2.13.0 Support visibility conditions |
| 13 | * @since 2.22.0 Add TapNode trait |
| 14 | */ |
| 15 | abstract class Field implements Node |
| 16 | { |
| 17 | use Concerns\HasDefaultValue; |
| 18 | use Concerns\HasName; |
| 19 | use Concerns\HasType; |
| 20 | use Concerns\HasVisibilityConditions; |
| 21 | use Concerns\IsReadOnly; |
| 22 | use Concerns\IsRequired; |
| 23 | use Concerns\Macroable; |
| 24 | use Concerns\SerializeAsJson; |
| 25 | use Concerns\TapNode; |
| 26 | use HasValidationRules { |
| 27 | HasValidationRules::__construct as private __validationRulesConstruct; |
| 28 | } |
| 29 | |
| 30 | /** |
| 31 | * @since 2.12.0 |
| 32 | * @since 2.23.1 Make constructor final to avoid unsafe usage of `new static()`. |
| 33 | * |
| 34 | * @throws EmptyNameException |
| 35 | */ |
| 36 | final public function __construct(string $name) |
| 37 | { |
| 38 | if (!$name) { |
| 39 | throw new EmptyNameException(); |
| 40 | } |
| 41 | |
| 42 | $this->name = $name; |
| 43 | $this->__validationRulesConstruct(); |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * @inheritDoc |
| 48 | */ |
| 49 | public function getNodeType(): string |
| 50 | { |
| 51 | return 'field'; |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * Create a named field. |
| 56 | * |
| 57 | * @since 2.12.0 |
| 58 | * |
| 59 | * @return static |
| 60 | * @throws EmptyNameException |
| 61 | */ |
| 62 | public static function make(string $name): self |
| 63 | { |
| 64 | if (!$name) { |
| 65 | throw new EmptyNameException(); |
| 66 | } |
| 67 | |
| 68 | return new static($name); |
| 69 | } |
| 70 | } |
| 71 |