-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat!: add schema attributes and reflection of static info
- Loading branch information
1 parent
e8017ef
commit 926f5ef
Showing
23 changed files
with
1,291 additions
and
209 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
/* | ||
* Copyright 2024 Cloud Creativity Limited | ||
* | ||
* Use of this source code is governed by an MIT-style | ||
* license that can be found in the LICENSE file or at | ||
* https://opensource.org/licenses/MIT. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace LaravelJsonApi\Contracts\Schema\StaticSchema; | ||
|
||
use LaravelJsonApi\Contracts\Schema\Schema; | ||
|
||
interface ServerConventions | ||
{ | ||
/** | ||
* Resolve the JSON:API resource type for the provided schema. | ||
* | ||
* @param class-string<Schema> $schema | ||
* @return non-empty-string | ||
*/ | ||
public function getTypeFor(string $schema): string; | ||
|
||
/** | ||
* Resolve the JSON:API resource type as it appears in URIs, for the provided resource type. | ||
* | ||
* @param non-empty-string $type | ||
* @return non-empty-string|null | ||
*/ | ||
public function getUriTypeFor(string $type): ?string; | ||
|
||
/** | ||
* @param class-string<Schema> $schema | ||
* @return class-string | ||
*/ | ||
public function getResourceClassFor(string $schema): string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?php | ||
/* | ||
* Copyright 2024 Cloud Creativity Limited | ||
* | ||
* Use of this source code is governed by an MIT-style | ||
* license that can be found in the LICENSE file or at | ||
* https://opensource.org/licenses/MIT. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace LaravelJsonApi\Contracts\Schema\StaticSchema; | ||
|
||
use IteratorAggregate; | ||
use LaravelJsonApi\Contracts\Schema\Schema; | ||
use LaravelJsonApi\Core\Values\ResourceType; | ||
|
||
/** | ||
* @implements IteratorAggregate<StaticSchema> | ||
*/ | ||
interface StaticContainer extends IteratorAggregate | ||
{ | ||
/** | ||
* Get a static schema for the specified schema class. | ||
* | ||
* @param class-string<Schema>|Schema $schema | ||
* @return StaticSchema | ||
*/ | ||
public function schemaFor(string|Schema $schema): StaticSchema; | ||
|
||
/** | ||
* Does a schema exist for the supplied JSON:API resource type? | ||
* | ||
* @param ResourceType|non-empty-string $type | ||
* @return bool | ||
*/ | ||
public function exists(ResourceType|string $type): bool; | ||
|
||
/** | ||
* Get the (non-static) schema class for a JSON:API resource type. | ||
* | ||
* @param ResourceType|non-empty-string $type | ||
* @return class-string<Schema> | ||
*/ | ||
public function schemaClassFor(ResourceType|string $type): string; | ||
|
||
/** | ||
* Get the fully qualified model class for the provided JSON:API resource type. | ||
* | ||
* @param ResourceType|non-empty-string $type | ||
* @return string | ||
*/ | ||
public function modelClassFor(ResourceType|string $type): string; | ||
|
||
/** | ||
* Get the JSON:API resource type for the provided type as it appears in URLs. | ||
* | ||
* @param non-empty-string $uriType | ||
* @return ResourceType|null | ||
*/ | ||
public function typeForUri(string $uriType): ?ResourceType; | ||
|
||
/** | ||
* Get a list of all the supported JSON:API resource types. | ||
* | ||
* @return array<non-empty-string> | ||
*/ | ||
public function types(): array; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
/* | ||
* Copyright 2024 Cloud Creativity Limited | ||
* | ||
* Use of this source code is governed by an MIT-style | ||
* license that can be found in the LICENSE file or at | ||
* https://opensource.org/licenses/MIT. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace LaravelJsonApi\Contracts\Schema\StaticSchema; | ||
|
||
use LaravelJsonApi\Contracts\Schema\Schema; | ||
|
||
interface StaticSchema | ||
{ | ||
/** | ||
* Get the schema class. | ||
* | ||
* @return class-string<Schema> | ||
*/ | ||
public function getSchemaClass(): string; | ||
|
||
/** | ||
* Get the JSON:API resource type. | ||
* | ||
* @return non-empty-string | ||
*/ | ||
public function getType(): string; | ||
|
||
/** | ||
* Get the JSON:API resource type as it appears in URIs. | ||
* | ||
* @return non-empty-string | ||
*/ | ||
public function getUriType(): string; | ||
|
||
/** | ||
* Get the fully-qualified class name of the model. | ||
* | ||
* @return class-string | ||
*/ | ||
public function getModel(): string; | ||
|
||
/** | ||
* Get the fully-qualified class name of the resource. | ||
* | ||
* @return class-string | ||
*/ | ||
public function getResourceClass(): string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
/* | ||
* Copyright 2024 Cloud Creativity Limited | ||
* | ||
* Use of this source code is governed by an MIT-style | ||
* license that can be found in the LICENSE file or at | ||
* https://opensource.org/licenses/MIT. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace LaravelJsonApi\Contracts\Schema\StaticSchema; | ||
|
||
use Generator; | ||
use LaravelJsonApi\Contracts\Schema\Schema; | ||
|
||
interface StaticSchemaFactory | ||
{ | ||
/** | ||
* Make static schemas for the provided schema classes. | ||
* | ||
* @param iterable<class-string<Schema>> $schemas | ||
* @return Generator<StaticSchema> | ||
*/ | ||
public function make(iterable $schemas): Generator; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
/* | ||
* Copyright 2024 Cloud Creativity Limited | ||
* | ||
* Use of this source code is governed by an MIT-style | ||
* license that can be found in the LICENSE file or at | ||
* https://opensource.org/licenses/MIT. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace LaravelJsonApi\Core\Schema\Attributes; | ||
|
||
use Attribute; | ||
|
||
#[Attribute(Attribute::TARGET_CLASS)] | ||
final readonly class Model | ||
{ | ||
/** | ||
* Model constructor. | ||
* | ||
* @param class-string $value | ||
*/ | ||
public function __construct(public string $value) | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
/* | ||
* Copyright 2024 Cloud Creativity Limited | ||
* | ||
* Use of this source code is governed by an MIT-style | ||
* license that can be found in the LICENSE file or at | ||
* https://opensource.org/licenses/MIT. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace LaravelJsonApi\Core\Schema\Attributes; | ||
|
||
use Attribute; | ||
|
||
#[Attribute(Attribute::TARGET_CLASS)] | ||
final readonly class ResourceClass | ||
{ | ||
/** | ||
* ResourceClass constructor. | ||
* | ||
* @param class-string $value | ||
*/ | ||
public function __construct(public string $value) | ||
{ | ||
} | ||
} |
Oops, something went wrong.