PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.16.8.1
GiveWP – Donation Plugin and Fundraising Platform v4.16.8.1
4.16.9 4.16.8.1 4.16.8 4.16.7.2 4.16.7.1 4.16.7 4.16.6.1 4.16.6 4.16.5.1 4.16.5 4.16.4 4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 2.30.0 All 255 releases
give / src / Framework / FieldsAPI / Field.php

Field.php in GiveWP – Donation Plugin and Fundraising Platform 4.16.8.1, at src/Framework/FieldsAPI/Field.php

81 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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\Framework\FieldsAPI\ValueObjects\PersistenceScope;
8 use Give\Vendors\StellarWP\Validation\Concerns\HasValidationRules;
9
10 /**
11 * @since 2.27.3 add ShowInAdmin, ShowInReceipt, StoreAsMeta
12 * @since 2.17.0 allow fields to be macroable
13 * @since 2.12.0
14 * @since 2.13.0 Support visibility conditions
15 * @since 2.22.0 Add TapNode trait
16 */
17 abstract class Field implements Node
18 {
19 use Concerns\HasDefaultValue;
20 use Concerns\HasName;
21 use Concerns\HasType;
22 use Concerns\HasPersistence;
23 use Concerns\IsReadOnly;
24 use Concerns\IsRequired;
25 use Concerns\Macroable;
26 use Concerns\SerializeAsJson;
27 use Concerns\TapNode;
28 use Concerns\ShowInAdmin;
29 use Concerns\ShowInReceipt;
30 use Concerns\HasVisibilityConditions {
31 Concerns\HasVisibilityConditions::__construct as private __visibilityConditionsConstruct;
32 }
33 use HasValidationRules {
34 HasValidationRules::__construct as private __validationRulesConstruct;
35 }
36
37 /**
38 * @since 2.32.0 sets the default scope to donation
39 * @since 2.23.1 make constructor final to avoid unsafe usage of `new static()`.
40 * @since 2.12.0
41 *
42 * @throws EmptyNameException
43 */
44 final public function __construct(string $name)
45 {
46 if (!$name) {
47 throw new EmptyNameException();
48 }
49
50 $this->name = $name;
51 $this->scope = PersistenceScope::donation();
52 $this->__validationRulesConstruct();
53 $this->__visibilityConditionsConstruct();
54 }
55
56 /**
57 * @inheritDoc
58 */
59 public function getNodeType(): string
60 {
61 return 'field';
62 }
63
64 /**
65 * Create a named field.
66 *
67 * @since 2.12.0
68 *
69 * @return static
70 * @throws EmptyNameException
71 */
72 public static function make(string $name): self
73 {
74 if (!$name) {
75 throw new EmptyNameException();
76 }
77
78 return new static($name);
79 }
80 }
81