-
-
Notifications
You must be signed in to change notification settings - Fork 239
FEATURE: Asset usage generic compatiblility with value objects in node properties #5683
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 9.1
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Neos\Media\Domain\Model; | ||
|
|
||
| final readonly class AssetId | ||
| { | ||
| private function __construct( | ||
| public string $value | ||
| ) { | ||
| } | ||
|
|
||
| public static function fromString(string $value): self | ||
| { | ||
| return new self($value); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Neos\Neos\AssetUsage; | ||
|
|
||
| use Neos\Media\Domain\Model\AssetId; | ||
|
|
||
| interface ProvidesAssetIdsInterface | ||
| { | ||
| /** | ||
| * @return list<AssetId> | ||
| */ | ||
| public function getAssetIds(): array; | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i went with an "always plural" interface as we have to account for the empty case and that a value object handles more than one asset too. So this seems the best fit. Also we should probably specify
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Iterable wound indeed be a better fit than array. |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,7 +15,10 @@ | |
| namespace Neos\Neos\Domain\Link; | ||
|
|
||
| use GuzzleHttp\Psr7\Uri; | ||
| use Neos\ContentRepository\Core\SharedModel\Node\NodeAggregateId; | ||
| use Neos\Flow\Annotations as Flow; | ||
| use Neos\Media\Domain\Model\AssetId; | ||
| use Neos\Neos\AssetUsage\ProvidesAssetIdsInterface; | ||
| use Psr\Http\Message\UriInterface; | ||
|
|
||
| /** | ||
|
|
@@ -38,7 +41,7 @@ | |
| * | ||
| * @Flow\Proxy(false) | ||
| */ | ||
| final readonly class Link implements \JsonSerializable | ||
| final readonly class Link implements \JsonSerializable, ProvidesAssetIdsInterface | ||
| { | ||
| /** | ||
| * A selection of frequently used target attribute values | ||
|
|
@@ -160,6 +163,35 @@ public function withDownload(bool $download): self | |
| ); | ||
| } | ||
|
|
||
| public function extractForScheme(string $scheme): string|null | ||
| { | ||
| if ($this->href->getScheme() !== $scheme) { | ||
| return null; | ||
| } | ||
| return $this->href->getHost() . $this->href->getPath(); | ||
| } | ||
|
|
||
| public function extractNodeAggregateId(): ?NodeAggregateId | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm a big fan of tryExtractWhatever if whatever is nullable, for readability |
||
| { | ||
| $rawNodeId = $this->extractForScheme('node'); | ||
| return $rawNodeId ? NodeAggregateId::fromString($rawNodeId) : null; | ||
| } | ||
|
|
||
| public function extractAssetId(): ?AssetId | ||
| { | ||
| $rawAssetId = $this->extractForScheme('asset'); | ||
| return $rawAssetId ? AssetId::fromString($rawAssetId) : null; | ||
| } | ||
|
|
||
| /** | ||
| * @return list<AssetId> | ||
| */ | ||
| public function getAssetIds(): array | ||
| { | ||
| $assetId = $this->extractAssetId(); | ||
| return $assetId ? [$assetId] : []; | ||
| } | ||
|
|
||
| public function jsonSerialize(): mixed | ||
| { | ||
| return [ | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The name sounds a bit strange why not
AssetIdProviderInterface