1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Bakery; |
4
|
|
|
|
5
|
|
|
use Bakery\Support\TypeRegistry; |
6
|
|
|
use Bakery\Types\Definitions\InternalType; |
7
|
|
|
|
8
|
|
|
class Type |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* Get the current bound registry. |
12
|
|
|
*/ |
13
|
|
|
public static function getRegistry(): TypeRegistry |
14
|
|
|
{ |
15
|
|
|
return resolve(TypeRegistry::class); |
16
|
|
|
} |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @return \Bakery\Types\Definitions\InternalType |
20
|
|
|
*/ |
21
|
|
|
public static function string(): InternalType |
22
|
|
|
{ |
23
|
|
|
return self::getRegistry()->string(); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @return \Bakery\Types\Definitions\InternalType |
28
|
|
|
*/ |
29
|
|
|
public static function int(): InternalType |
30
|
|
|
{ |
31
|
|
|
return self::getRegistry()->int(); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @return \Bakery\Types\Definitions\InternalType |
36
|
|
|
*/ |
37
|
|
|
public static function ID(): InternalType |
38
|
|
|
{ |
39
|
|
|
return self::getRegistry()->ID(); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @return \Bakery\Types\Definitions\InternalType |
44
|
|
|
*/ |
45
|
|
|
public static function boolean(): InternalType |
46
|
|
|
{ |
47
|
|
|
return self::getRegistry()->boolean(); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @return \Bakery\Types\Definitions\InternalType |
52
|
|
|
*/ |
53
|
|
|
public static function float(): InternalType |
54
|
|
|
{ |
55
|
|
|
return self::getRegistry()->float(); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Create a new type by reference. |
60
|
|
|
* |
61
|
|
|
* @param string $name |
62
|
|
|
* @return \Bakery\Types\Definitions\RootType |
63
|
|
|
*/ |
64
|
|
|
public static function of(string $name): Types\Definitions\RootType |
65
|
|
|
{ |
66
|
|
|
return self::getRegistry()->type($name); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Create a new type for a model schema. |
71
|
|
|
* |
72
|
|
|
* @param string $class |
73
|
|
|
* @return \Bakery\Types\Definitions\RootType |
74
|
|
|
*/ |
75
|
|
|
public static function modelSchema(string $class): Types\Definitions\RootType |
76
|
|
|
{ |
77
|
|
|
$modelSchema = self::getRegistry()->getModelSchema($class); |
78
|
|
|
|
79
|
|
|
return self::getRegistry()->type($modelSchema->getTypename()); |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|