1 | <?php |
||
14 | class GraphQLField |
||
15 | { |
||
16 | |||
17 | /** |
||
18 | * @var mixed $name |
||
19 | */ |
||
20 | protected $name; |
||
21 | |||
22 | |||
23 | /** |
||
24 | * @param string $name |
||
25 | * @param array $config |
||
26 | * @throws InvalidArgumentException |
||
27 | */ |
||
28 | public function __construct($name, array $config = []) |
||
33 | |||
34 | |||
35 | /** |
||
36 | * @param array $config |
||
37 | * @throws InvalidArgumentException |
||
38 | */ |
||
39 | public function setProps(array $config) |
||
45 | |||
46 | |||
47 | /** |
||
48 | * Get the field name. |
||
49 | * |
||
50 | * @return string |
||
51 | */ |
||
52 | public function name() |
||
56 | |||
57 | |||
58 | /** |
||
59 | * Get the model key of the field. |
||
60 | * |
||
61 | * @return string|null |
||
62 | */ |
||
63 | public function key() |
||
70 | |||
71 | |||
72 | /** |
||
73 | * Get the caps required for the field. |
||
74 | * |
||
75 | * @return array |
||
76 | */ |
||
77 | public function caps() |
||
84 | |||
85 | |||
86 | /** |
||
87 | * Whether the field should resolve |
||
88 | * based on the user caps etc. |
||
89 | * @return boolean |
||
90 | */ |
||
91 | public function shouldResolve() |
||
100 | |||
101 | |||
102 | /** |
||
103 | * Whether the field has an explicit resolver set. |
||
104 | * @return boolean |
||
105 | */ |
||
106 | public function hasInternalResolver() |
||
110 | |||
111 | |||
112 | /** |
||
113 | * Checks if the format callback is set. |
||
114 | * If yes, then uses it to format the value. |
||
115 | * @param mixed $value |
||
116 | * @return mixed The formatted value. |
||
117 | */ |
||
118 | public function mayBeFormatValue($value) |
||
125 | |||
126 | |||
127 | /** |
||
128 | * Convert the field to array to be |
||
129 | * able to pass as config to WP GraphQL |
||
130 | * @return array |
||
131 | */ |
||
132 | public function toArray() |
||
136 | } |
||
137 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: