File tree Expand file tree Collapse file tree 2 files changed +10
-23
lines changed Expand file tree Collapse file tree 2 files changed +10
-23
lines changed Original file line number Diff line number Diff line change @@ -31,13 +31,9 @@ public function __construct(string $baseUrl)
31
31
$ this ->baseUrl = $ baseUrl ;
32
32
}
33
33
34
- public function resource (string $ type ): ResourceType
34
+ public function resource (string $ type, $ adapter , Closure $ buildSchema = null ): void
35
35
{
36
- if (! isset ($ this ->resources [$ type ])) {
37
- $ this ->resources [$ type ] = new ResourceType ($ type );
38
- }
39
-
40
- return $ this ->resources [$ type ];
36
+ $ this ->resources [$ type ] = new ResourceType ($ type , $ adapter , $ buildSchema );
41
37
}
42
38
43
39
public function getResources (): array
Original file line number Diff line number Diff line change 2
2
3
3
namespace Tobyz \JsonApiServer ;
4
4
5
+ use Closure ;
5
6
use Tobyz \JsonApiServer \Adapter \AdapterInterface ;
6
7
use Tobyz \JsonApiServer \Schema \Type ;
7
8
8
9
final class ResourceType
9
10
{
10
11
private $ type ;
11
12
private $ adapter ;
12
- private $ schemaCallbacks = [] ;
13
+ private $ buildSchema ;
13
14
private $ schema ;
14
15
15
- public function __construct (string $ type )
16
+ public function __construct (string $ type, AdapterInterface $ adapter , Closure $ buildSchema = null )
16
17
{
17
18
$ this ->type = $ type ;
19
+ $ this ->adapter = $ adapter ;
20
+ $ this ->buildSchema = $ buildSchema ;
18
21
}
19
22
20
23
public function getType (): string
21
24
{
22
25
return $ this ->type ;
23
26
}
24
27
25
- public function adapter (AdapterInterface $ adapter )
26
- {
27
- $ this ->adapter = $ adapter ;
28
-
29
- return $ this ;
30
- }
31
-
32
28
public function getAdapter (): AdapterInterface
33
29
{
34
30
return $ this ->adapter ;
35
31
}
36
32
37
- public function schema (callable $ callback )
38
- {
39
- $ this ->schemaCallbacks [] = $ callback ;
40
-
41
- return $ this ;
42
- }
43
-
44
33
public function getSchema (): Type
45
34
{
46
35
if (! $ this ->schema ) {
47
36
$ this ->schema = new Type ;
48
37
49
- run_callbacks ($ this ->schemaCallbacks , [$ this ->schema ]);
38
+ if ($ this ->buildSchema ) {
39
+ ($ this ->buildSchema )($ this ->schema );
40
+ }
50
41
}
51
42
52
43
return $ this ->schema ;
You can’t perform that action at this time.
0 commit comments