generated from gsteel/php-template-project
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add methods to manipulate shared slices
- Loading branch information
Showing
25 changed files
with
656 additions
and
26 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
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
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
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,44 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Prismic\DocumentType; | ||
|
||
use function json_encode; | ||
|
||
final class SharedSlice | ||
{ | ||
/** | ||
* @param non-empty-string $id | ||
* @param non-empty-string $json | ||
*/ | ||
private function __construct( | ||
public readonly string $id, | ||
public readonly string $json, | ||
) { | ||
} | ||
|
||
/** | ||
* @param non-empty-string $id | ||
* @param non-empty-string $json | ||
*/ | ||
public static function new(string $id, string $json): self | ||
{ | ||
return new self($id, $json); | ||
} | ||
|
||
/** @param array<array-key, mixed> $payload */ | ||
public static function fromArray(array $payload): self | ||
{ | ||
Assert::keyExists($payload, 'id'); | ||
Check warning on line 33 in src/SharedSlice.php GitHub Actions / Mutation Tests
Check warning on line 33 in src/SharedSlice.php GitHub Actions / Mutation Tests
|
||
Assert::stringNotEmpty($payload['id']); | ||
Check warning on line 34 in src/SharedSlice.php GitHub Actions / Mutation Tests
Check warning on line 34 in src/SharedSlice.php GitHub Actions / Mutation Tests
|
||
|
||
return new self($payload['id'], json_encode($payload)); | ||
} | ||
|
||
public function equals(SharedSlice $other): bool | ||
{ | ||
return $this->id === $other->id | ||
&& $this->json === $other->json; | ||
} | ||
} |
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,45 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Prismic\DocumentType; | ||
|
||
use Countable; | ||
use Prismic\DocumentType\Exception\DefinitionNotFound; | ||
use Prismic\DocumentType\Exception\Exception; | ||
|
||
interface SharedSliceManagementClient | ||
{ | ||
/** | ||
* Return a list of the Shared Slices found in the remote repo | ||
* | ||
* @return iterable<string, SharedSlice>&Countable | ||
*/ | ||
public function fetchAllSharedSlices(): iterable; | ||
|
||
/** | ||
* Insert or update a shared slice | ||
* | ||
* @throws Exception | ||
*/ | ||
public function saveSharedSlice(SharedSlice $slice): void; | ||
|
||
/** | ||
* Fetch a shared slice | ||
* | ||
* @param non-empty-string $id | ||
* | ||
* @throws DefinitionNotFound if there is no such type with the given id. | ||
* @throws Exception if any errors occur communicating with the remote API. | ||
*/ | ||
public function getSharedSlice(string $id): SharedSlice; | ||
|
||
/** | ||
* Deletes the shared slice with the given identifier | ||
* | ||
* @param non-empty-string $id | ||
* | ||
* @throws Exception if any errors occur communicating with the remote API. | ||
*/ | ||
public function deleteSharedSlice(string $id): void; | ||
} |
Oops, something went wrong.