22
33declare (strict_types=1 );
44
5- namespace Constructo \Core \Metadata \Schema ;
5+ namespace Constructo \Core \Metadata \Schema \ Registry ;
66
77use Constructo \Contract \Formatter ;
8- use Constructo \Core \Metadata \Schema \Registry \Spec ;
98use Constructo \Support \Set ;
109use InvalidArgumentException ;
1110
1211use function class_exists ;
13- use function Constructo \Cast \stringify ;
1412use function Constructo \Notation \snakify ;
1513use function gettype ;
1614use function is_string ;
1715use function sprintf ;
1816
19- class Registry
17+ class Specs
2018{
2119 private array $ specs = [];
22- private readonly array $ types ;
2320
24- public function __construct (array $ types = [])
25- {
26- $ this ->types = array_merge ($ this ->defaultTypes (), $ types );
27- }
28-
29- public function getSpec (string $ name ): ?Spec
21+ public function get (string $ name ): ?Spec
3022 {
3123 $ name = snakify ($ name );
3224 $ spec = $ this ->specs [$ name ] ?? null ;
@@ -36,7 +28,7 @@ public function getSpec(string $name): ?Spec
3628 return null ;
3729 }
3830
39- public function registerSpec (string $ name , array $ data ): void
31+ public function register (string $ name , array $ data ): void
4032 {
4133 $ name = snakify ($ name );
4234 $ properties = Set::createFrom ($ data );
@@ -46,20 +38,12 @@ public function registerSpec(string $name, array $data): void
4638 $ this ->specs [$ name ] = $ spec ;
4739 }
4840
49- public function hasSpec (string $ name ): bool
41+ public function has (string $ name ): bool
5042 {
5143 $ name = snakify ($ name );
5244 return isset ($ this ->specs [$ name ]);
5345 }
5446
55- public function getType (string $ source ): ?string
56- {
57- $ type = $ this ->types [$ source ] ?? null ;
58- return $ type
59- ? stringify ($ type )
60- : null ;
61- }
62-
6347 protected function defineFormatter (Set $ properties ): ?Formatter
6448 {
6549 $ formatter = $ properties ->get ('formatter ' );
@@ -79,13 +63,4 @@ protected function defineFormatter(Set $properties): ?Formatter
7963 }
8064 return $ instance ;
8165 }
82-
83- protected function defaultTypes (): array
84- {
85- return [
86- 'DateTime ' => 'date ' ,
87- 'DateTimeImmutable ' => 'date ' ,
88- 'DateTimeInterface ' => 'date ' ,
89- ];
90- }
9166}
0 commit comments