| 1 | <?php |
||
| 15 | class TypeFactory |
||
| 16 | { |
||
| 17 | private static $objectsHash = []; |
||
| 18 | |||
| 19 | /** |
||
| 20 | * @param string $type |
||
| 21 | * |
||
| 22 | * @throws ConfigurationException |
||
| 23 | * @return AbstractScalarType |
||
| 24 | */ |
||
| 25 | 119 | public static function getScalarType($type) |
|
| 26 | { |
||
| 27 | 119 | if (TypeService::isScalarType($type)) { |
|
| 28 | 119 | if (is_object($type)) { |
|
| 29 | 104 | return $type; |
|
| 30 | } |
||
| 31 | 97 | if (empty(self::$objectsHash[$type])) { |
|
| 32 | 5 | $name = ucfirst($type); |
|
| 33 | |||
| 34 | 5 | $name = $name == 'Datetime' ? 'DateTime' : $name; |
|
| 35 | 5 | $name = $name == 'Datetimetz' ? 'DateTimeTz' : $name; |
|
| 36 | |||
| 37 | 5 | $className = 'Youshido\GraphQL\Type\Scalar\\' . $name . 'Type'; |
|
| 38 | 5 | self::$objectsHash[$type] = new $className(); |
|
| 39 | 5 | } |
|
| 40 | |||
| 41 | 97 | return self::$objectsHash[$type]; |
|
| 42 | } else { |
||
| 43 | 1 | throw new ConfigurationException('Configuration problem with type ' . $type); |
|
| 44 | } |
||
| 45 | } |
||
| 46 | |||
| 47 | /** |
||
| 48 | * @return string[] |
||
| 49 | */ |
||
| 50 | 101 | public static function getScalarTypesNames() |
|
| 64 | } |
||
| 65 |