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
24 changed files
with
639 additions
and
25 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'); | ||
Assert::stringNotEmpty($payload['id']); | ||
|
||
return new self($payload['id'], json_encode($payload)); | ||
} | ||
|
||
public function equals(SharedSlice $other): bool | ||
{ | ||
return $this->id === $other->id | ||
&& $this->json === $other->json; | ||
} | ||
} |
Oops, something went wrong.