1 | <?php |
||
19 | class TypeService |
||
20 | { |
||
21 | |||
22 | const TYPE_CALLABLE = 'callable'; |
||
23 | const TYPE_GRAPHQL_TYPE = 'graphql_type'; |
||
24 | const TYPE_OBJECT_TYPE = 'object_type'; |
||
25 | const TYPE_ARRAY_OF_OBJECT_TYPES = 'array_of_object_types'; |
||
26 | const TYPE_OBJECT_INPUT_TYPE = 'object_input_type'; |
||
27 | const TYPE_LIST = 'list'; |
||
28 | const TYPE_BOOLEAN = TypeMap::TYPE_BOOLEAN; |
||
29 | const TYPE_STRING = TypeMap::TYPE_STRING; |
||
30 | const TYPE_ARRAY = 'array'; |
||
31 | const TYPE_ARRAY_OF_FIELDS_CONFIG = 'array_of_fields'; |
||
32 | const TYPE_ARRAY_OF_INPUT_FIELDS = 'array_of_inputs'; |
||
33 | const TYPE_ENUM_VALUES = 'array_of_values'; |
||
34 | const TYPE_ARRAY_OF_INTERFACES = 'array_of_interfaces'; |
||
35 | const TYPE_ANY = 'any'; |
||
36 | const TYPE_ANY_OBJECT = 'any_object'; |
||
37 | const TYPE_ANY_INPUT = 'any_input'; |
||
38 | |||
39 | 2 | public static function resolveNamedType($object) |
|
53 | |||
54 | /** |
||
55 | * @param AbstractType|mixed $type |
||
56 | * @return bool |
||
57 | */ |
||
58 | 2 | public static function isInterface($type) |
|
66 | |||
67 | /** |
||
68 | * @param AbstractType|mixed $type |
||
69 | * @return bool |
||
70 | */ |
||
71 | 3 | public static function isAbstractType($type) |
|
79 | |||
80 | 123 | public static function isScalarType($type) |
|
88 | |||
89 | 91 | public static function isGraphQLType($type) |
|
93 | |||
94 | public static function isLeafType($type) |
||
98 | |||
99 | 8 | public static function isObjectType($type) |
|
103 | |||
104 | /** |
||
105 | * @param mixed|AbstractType $type |
||
106 | * @return bool |
||
107 | */ |
||
108 | 6 | public static function isInputType($type) |
|
121 | |||
122 | 2 | public static function isInputObjectType($type) |
|
126 | |||
127 | 11 | public static function getPropertyValue($data, $path) |
|
128 | { |
||
129 | 11 | if (is_object($data)) { |
|
130 | 11 | $getter = $path; |
|
131 | 11 | if (substr($path, 0, 2) != 'is') { |
|
132 | 11 | $getter = 'get' . self::classify($path); |
|
133 | 11 | if (!is_callable([$data, $getter])) { |
|
134 | 1 | $getter = 'is' . self::classify($path); |
|
135 | 1 | } |
|
136 | 11 | if (!is_callable([$data, $getter])) { |
|
137 | 1 | $getter = self::classify($path); |
|
138 | 1 | } |
|
139 | 11 | } |
|
140 | |||
141 | 11 | return is_callable([$data, $getter]) ? $data->$getter() : (isset($data->$path) ? $data->$path : null); |
|
142 | 1 | } elseif (is_array($data)) { |
|
143 | 1 | return array_key_exists($path, $data) ? $data[$path] : null; |
|
144 | } |
||
145 | |||
146 | return null; |
||
147 | } |
||
148 | |||
149 | 11 | protected static function classify($text) |
|
160 | } |
||
161 |