Skip to content

Commit d889701

Browse files
committed
Revert "Update resource definition API to allow extending schema"
This reverts commit 57ffa86.
1 parent 1ccbe65 commit d889701

File tree

2 files changed

+10
-23
lines changed

2 files changed

+10
-23
lines changed

src/JsonApi.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,9 @@ public function __construct(string $baseUrl)
3131
$this->baseUrl = $baseUrl;
3232
}
3333

34-
public function resource(string $type): ResourceType
34+
public function resource(string $type, $adapter, Closure $buildSchema = null): void
3535
{
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);
4137
}
4238

4339
public function getResources(): array

src/ResourceType.php

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,51 +2,42 @@
22

33
namespace Tobyz\JsonApiServer;
44

5+
use Closure;
56
use Tobyz\JsonApiServer\Adapter\AdapterInterface;
67
use Tobyz\JsonApiServer\Schema\Type;
78

89
final class ResourceType
910
{
1011
private $type;
1112
private $adapter;
12-
private $schemaCallbacks = [];
13+
private $buildSchema;
1314
private $schema;
1415

15-
public function __construct(string $type)
16+
public function __construct(string $type, AdapterInterface $adapter, Closure $buildSchema = null)
1617
{
1718
$this->type = $type;
19+
$this->adapter = $adapter;
20+
$this->buildSchema = $buildSchema;
1821
}
1922

2023
public function getType(): string
2124
{
2225
return $this->type;
2326
}
2427

25-
public function adapter(AdapterInterface $adapter)
26-
{
27-
$this->adapter = $adapter;
28-
29-
return $this;
30-
}
31-
3228
public function getAdapter(): AdapterInterface
3329
{
3430
return $this->adapter;
3531
}
3632

37-
public function schema(callable $callback)
38-
{
39-
$this->schemaCallbacks[] = $callback;
40-
41-
return $this;
42-
}
43-
4433
public function getSchema(): Type
4534
{
4635
if (! $this->schema) {
4736
$this->schema = new Type;
4837

49-
run_callbacks($this->schemaCallbacks, [$this->schema]);
38+
if ($this->buildSchema) {
39+
($this->buildSchema)($this->schema);
40+
}
5041
}
5142

5243
return $this->schema;

0 commit comments

Comments
 (0)