PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 2.19.6
GiveWP – Donation Plugin and Fundraising Platform v2.19.6
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 2.31.0 2.31.1 All 253 releases
give / src / Framework / FieldsAPI / Field.php

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

65 lines 1.3 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\Concerns\ValidationRules;
6 use Give\Framework\FieldsAPI\Contracts\Node;
7 use Give\Framework\FieldsAPI\Exceptions\EmptyNameException;
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 */
14 abstract class Field implements Node
15 {
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
26 /** @var ValidationRules */
27 protected $validationRules;
28
29 /**
30 * @since 2.12.0
31 *
32 * @param string $name
33 *
34 * @throws EmptyNameException
35 */
36 public function __construct($name)
37 {
38 if ( ! $name) {
39 throw new EmptyNameException();
40 }
41
42 $this->name = $name;
43 $this->validationRules = new ValidationRules();
44 }
45
46 /**
47 * Create a named field.
48 *
49 * @since 2.12.0
50 *
51 * @param string $name
52 *
53 * @return static
54 * @throws EmptyNameException
55 */
56 public static function make($name)
57 {
58 if ( ! $name) {
59 throw new EmptyNameException();
60 }
61
62 return new static($name);
63 }
64 }
65