From 9a5fd6af53c9d6aace2f88426f116bee49d5d14a Mon Sep 17 00:00:00 2001 From: Akihito Koriyama Date: Tue, 24 Nov 2026 09:30:24 +0900 Subject: [PATCH 1/5] Resolve a path-only collection href under the write's scheme and host HAL renders an app:// href as written, so a #[Link] meant for HAL is written path-only (/posts), which purged nothing. A path-only href now names the resource under the scheme and host of the URI the write was sent to, so one #[Link] serves both HAL and the purge. A resource taken from the injector has no URI, and its path-only href is still skipped. --- CHANGELOG.md | 2 +- docs/llms-full.txt | 2 +- src/RefreshAnnotatedCommand.php | 17 ++++++++++++++++- tests/CollectionLinkTest.php | 4 ++-- .../src/Resource/App/Collection/Comment.php | 2 +- 5 files changed, 21 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 73ed07db..70364379 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] ### Added -- `#[Link(rel: 'collection', href: ...)]` on a row's `onGet()` names the list it belongs to: a write to the row purges the list's URI and the variants that differ only in default-valued parameters, so the list needs no `#[DependsOn]` for its rows. +- `#[Link(rel: 'collection', href: ...)]` on a row's `onGet()` names the list it belongs to: a write to the row purges the list's URI and the variants that differ only in default-valued parameters, so the list needs no `#[DependsOn]` for its rows. A path-only href, as HAL writes it (`/posts`), names the list under the row's own scheme and host. - The `purge_skipped` log entry (fields `uri`, the write's URI without its query, and `reason`, `unmatched_query`), recorded when a write on a resource without a cache attribute cannot address its own key because its query lacks a required `onGet()` parameter. - `AppSurrogateKeyModule($key)` adds the key to every entry this package stores and to every `Surrogate-Key` it sets, so invalidating the key on the server and at the CDN clears the whole application. Install it before or after `QueryRepositoryModule`. - `#[DependsOn(uri: ..., key: ...)]`: `key` names the rows in the body `onGet()` returns, so `#[DependsOn(uri: 'app://self/article?id={id}', key: 'articles')]` with `$this->body['articles'] = [['id' => 1, ...], ['id' => 2, ...]]` depends on `?id=1` and `?id=2`; a row that lacks the variable is skipped, an empty list names no URI, and a variable no row holds is read from the body's top level, then from the arguments. A body or row list that can be read only once, such as a `Generator`, is left in the body as an `ArrayIterator` with every row, under the keys it yielded unless a key repeats, as with `yield from`, which leaves a list. diff --git a/docs/llms-full.txt b/docs/llms-full.txt index a955ca4a..35433c88 100644 --- a/docs/llms-full.txt +++ b/docs/llms-full.txt @@ -143,7 +143,7 @@ class Article extends ResourceObject ``` - The purge reaches every variant of the collection that differs only in default-valued parameters (see Purging query variants): with `onGet(?int $authorId = null, int $page = 1)`, purging `app://self/articles` drops `?page=2` and `?author_id=7`. A list keyed by a required parameter, such as one author's articles, is another group: name it with `#[Purge]` on the write. -- The href expands as a `#[Purge]` template does, from the body the write returns, then from its query. An href that does not expand to a resource URI, such as a path-only one, and a `#[Link]` of another rel purge nothing. +- The href expands as a `#[Purge]` template does, from the body the write returns, then from its query. A path-only href, as HAL writes it (`/articles`), names a resource under the row's own scheme and host, so one `#[Link]` serves both HAL and the purge; an href that does not expand to a resource URI and a `#[Link]` of another rel purge nothing. - Which side declares the relation: when the list knows its rows and their number is bounded, declare `#[DependsOn]` on the list; when the row knows its list and the rows are unbounded, declare `#[Link(rel: 'collection')]` on the row. The collection link keeps the list to its own key. - A write that moves a row from one list to another names both lists with `#[Purge]`. The old value comes from the body the write returns, under a name other than the argument's, as the body is read before the query: diff --git a/src/RefreshAnnotatedCommand.php b/src/RefreshAnnotatedCommand.php index 43da4274..739d3d83 100644 --- a/src/RefreshAnnotatedCommand.php +++ b/src/RefreshAnnotatedCommand.php @@ -20,6 +20,7 @@ use function array_values; use function is_array; use function method_exists; +use function str_starts_with; use function uri_template; /** @internal */ @@ -61,7 +62,7 @@ public function declared(MethodInvocation $invocation, ResourceObject $ro): arra $target = $invocation->getThis(); if ($target instanceof ResourceObject) { foreach ($this->collections($target) as $href) { - $declared[] = [$this->resourceUris($this->uris($ro, $href, $query)), false]; + $declared[] = [$this->resourceUris($this->uris($ro, $this->resolved($href, $uri), $query)), false]; } } @@ -122,6 +123,20 @@ private function uris(ResourceObject $ro, string $template, array $query): array return array_values(array_unique($uris)); } + /** A path-only href, as HAL writes it, names a resource of the write's own scheme and host */ + private function resolved(string $href, AbstractUri|null $uri): string + { + if ($uri === null) { + return $href; + } + + if (! str_starts_with($href, '/') || str_starts_with($href, '//')) { + return $href; + } + + return "{$uri->scheme}://{$uri->host}{$href}"; + } + /** * @param list $uris * diff --git a/tests/CollectionLinkTest.php b/tests/CollectionLinkTest.php index 8f05ac1e..660275ed 100644 --- a/tests/CollectionLinkTest.php +++ b/tests/CollectionLinkTest.php @@ -63,8 +63,8 @@ public function testOnlyTheCollectionIsPurged(): void $this->assertNotNull($this->repository->get(new Uri($authorPosts))); } - /** An href that is not a resource URI, as a path-only one, is skipped after the write has run */ - public function testHrefThatIsNotAResourceUriIsSkipped(): void + /** A path-only href names the list under the write's own scheme and host; an href that is not a resource URI is skipped */ + public function testPathOnlyHrefIsResolvedAndAnUnusableOneSkipped(): void { $posts = 'app://self/collection/posts'; $this->resource->get($posts); diff --git a/tests/Fake/fake-app/src/Resource/App/Collection/Comment.php b/tests/Fake/fake-app/src/Resource/App/Collection/Comment.php index 57449dd1..8dd136dc 100644 --- a/tests/Fake/fake-app/src/Resource/App/Collection/Comment.php +++ b/tests/Fake/fake-app/src/Resource/App/Collection/Comment.php @@ -10,7 +10,7 @@ class Comment extends ResourceObject { #[Link(rel: 'collection', href: '/collection/posts')] - #[Link(rel: 'collection', href: 'app://self/collection/posts')] + #[Link(rel: 'collection', href: '')] public function onGet(int $id): static { $this->body = ['id' => $id]; From 12c4ed0f63e82bf99aafd2d8524cbd4a40545bc1 Mon Sep 17 00:00:00 2001 From: Akihito Koriyama Date: Tue, 24 Nov 2026 09:40:28 +0900 Subject: [PATCH 2/5] Resolve a collection href that expands to a path The href is tested after uri_template() expands it, so a template that starts with an expression ({/kind}/posts) is resolved like a literal path. The docs say the list is named by its path, since the purge tag carries no scheme or host. --- CHANGELOG.md | 2 +- docs/llms-full.txt | 2 +- src/RefreshAnnotatedCommand.php | 5 +++-- tests/CollectionLinkTest.php | 4 ++-- tests/Fake/fake-app/src/Resource/App/Collection/Comment.php | 4 ++-- 5 files changed, 9 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 70364379..7fb16bca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] ### Added -- `#[Link(rel: 'collection', href: ...)]` on a row's `onGet()` names the list it belongs to: a write to the row purges the list's URI and the variants that differ only in default-valued parameters, so the list needs no `#[DependsOn]` for its rows. A path-only href, as HAL writes it (`/posts`), names the list under the row's own scheme and host. +- `#[Link(rel: 'collection', href: ...)]` on a row's `onGet()` names the list it belongs to: a write to the row purges the list's URI and the variants that differ only in default-valued parameters, so the list needs no `#[DependsOn]` for its rows. A path-only href, as HAL writes it (`/posts`), names the list at that path. - The `purge_skipped` log entry (fields `uri`, the write's URI without its query, and `reason`, `unmatched_query`), recorded when a write on a resource without a cache attribute cannot address its own key because its query lacks a required `onGet()` parameter. - `AppSurrogateKeyModule($key)` adds the key to every entry this package stores and to every `Surrogate-Key` it sets, so invalidating the key on the server and at the CDN clears the whole application. Install it before or after `QueryRepositoryModule`. - `#[DependsOn(uri: ..., key: ...)]`: `key` names the rows in the body `onGet()` returns, so `#[DependsOn(uri: 'app://self/article?id={id}', key: 'articles')]` with `$this->body['articles'] = [['id' => 1, ...], ['id' => 2, ...]]` depends on `?id=1` and `?id=2`; a row that lacks the variable is skipped, an empty list names no URI, and a variable no row holds is read from the body's top level, then from the arguments. A body or row list that can be read only once, such as a `Generator`, is left in the body as an `ArrayIterator` with every row, under the keys it yielded unless a key repeats, as with `yield from`, which leaves a list. diff --git a/docs/llms-full.txt b/docs/llms-full.txt index 35433c88..32fa8d9e 100644 --- a/docs/llms-full.txt +++ b/docs/llms-full.txt @@ -143,7 +143,7 @@ class Article extends ResourceObject ``` - The purge reaches every variant of the collection that differs only in default-valued parameters (see Purging query variants): with `onGet(?int $authorId = null, int $page = 1)`, purging `app://self/articles` drops `?page=2` and `?author_id=7`. A list keyed by a required parameter, such as one author's articles, is another group: name it with `#[Purge]` on the write. -- The href expands as a `#[Purge]` template does, from the body the write returns, then from its query. A path-only href, as HAL writes it (`/articles`), names a resource under the row's own scheme and host, so one `#[Link]` serves both HAL and the purge; an href that does not expand to a resource URI and a `#[Link]` of another rel purge nothing. +- The href expands as a `#[Purge]` template does, from the body the write returns, then from its query. An href that expands to a path, as HAL writes it (`/articles`), names the resource at that path, so one `#[Link]` serves both HAL and the purge; an href that does not expand to a resource URI and a `#[Link]` of another rel purge nothing. - Which side declares the relation: when the list knows its rows and their number is bounded, declare `#[DependsOn]` on the list; when the row knows its list and the rows are unbounded, declare `#[Link(rel: 'collection')]` on the row. The collection link keeps the list to its own key. - A write that moves a row from one list to another names both lists with `#[Purge]`. The old value comes from the body the write returns, under a name other than the argument's, as the body is read before the query: diff --git a/src/RefreshAnnotatedCommand.php b/src/RefreshAnnotatedCommand.php index 739d3d83..086466f7 100644 --- a/src/RefreshAnnotatedCommand.php +++ b/src/RefreshAnnotatedCommand.php @@ -62,7 +62,8 @@ public function declared(MethodInvocation $invocation, ResourceObject $ro): arra $target = $invocation->getThis(); if ($target instanceof ResourceObject) { foreach ($this->collections($target) as $href) { - $declared[] = [$this->resourceUris($this->uris($ro, $this->resolved($href, $uri), $query)), false]; + $expanded = array_map(fn (string $expandedHref): string => $this->resolved($expandedHref, $uri), $this->uris($ro, $href, $query)); + $declared[] = [$this->resourceUris($expanded), false]; } } @@ -123,7 +124,7 @@ private function uris(ResourceObject $ro, string $template, array $query): array return array_values(array_unique($uris)); } - /** A path-only href, as HAL writes it, names a resource of the write's own scheme and host */ + /** A path-only href, as HAL writes it, is a resource path; the scheme and host are the write's */ private function resolved(string $href, AbstractUri|null $uri): string { if ($uri === null) { diff --git a/tests/CollectionLinkTest.php b/tests/CollectionLinkTest.php index 660275ed..a34fd6d8 100644 --- a/tests/CollectionLinkTest.php +++ b/tests/CollectionLinkTest.php @@ -63,8 +63,8 @@ public function testOnlyTheCollectionIsPurged(): void $this->assertNotNull($this->repository->get(new Uri($authorPosts))); } - /** A path-only href names the list under the write's own scheme and host; an href that is not a resource URI is skipped */ - public function testPathOnlyHrefIsResolvedAndAnUnusableOneSkipped(): void + /** An href that expands to a path names the list at that path; an href that is not a resource URI is skipped */ + public function testHrefExpandingToAPathIsResolvedAndAnUnusableOneSkipped(): void { $posts = 'app://self/collection/posts'; $this->resource->get($posts); diff --git a/tests/Fake/fake-app/src/Resource/App/Collection/Comment.php b/tests/Fake/fake-app/src/Resource/App/Collection/Comment.php index 8dd136dc..c4836f6c 100644 --- a/tests/Fake/fake-app/src/Resource/App/Collection/Comment.php +++ b/tests/Fake/fake-app/src/Resource/App/Collection/Comment.php @@ -9,7 +9,7 @@ class Comment extends ResourceObject { - #[Link(rel: 'collection', href: '/collection/posts')] + #[Link(rel: 'collection', href: '{/kind}/posts')] #[Link(rel: 'collection', href: '')] public function onGet(int $id): static { @@ -20,7 +20,7 @@ public function onGet(int $id): static public function onPut(int $id): static { - $this->body = ['id' => $id]; + $this->body = ['id' => $id, 'kind' => 'collection']; return $this; } From 4ffb61cbdd82e9048cbab8afd45d5116f764fb29 Mon Sep 17 00:00:00 2001 From: Akihito Koriyama Date: Tue, 24 Nov 2026 09:46:05 +0900 Subject: [PATCH 3/5] Test that a row without a URI resolves no path-only href --- tests/CollectionLinkTest.php | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/tests/CollectionLinkTest.php b/tests/CollectionLinkTest.php index a34fd6d8..7177c5ce 100644 --- a/tests/CollectionLinkTest.php +++ b/tests/CollectionLinkTest.php @@ -6,6 +6,7 @@ use BEAR\Resource\ResourceInterface; use BEAR\Resource\Uri; +use FakeVendor\HelloWorld\Resource\App\Collection\Comment; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use Ray\Di\Injector; @@ -13,14 +14,15 @@ /** A write to a row purges the collection its onGet() links with #[Link(rel: 'collection')] */ class CollectionLinkTest extends TestCase { + private Injector $injector; private ResourceInterface $resource; private QueryRepositoryInterface $repository; protected function setUp(): void { - $injector = new Injector(ModuleFactory::getInstance('FakeVendor\HelloWorld'), __DIR__ . '/tmp'); - $this->resource = $injector->getInstance(ResourceInterface::class); - $this->repository = $injector->getInstance(QueryRepositoryInterface::class); + $this->injector = new Injector(ModuleFactory::getInstance('FakeVendor\HelloWorld'), __DIR__ . '/tmp'); + $this->resource = $this->injector->getInstance(ResourceInterface::class); + $this->repository = $this->injector->getInstance(QueryRepositoryInterface::class); $this->repository->purge(new Uri('app://self/collection/posts')); $this->repository->purge(new Uri('app://self/collection/author-posts?author_id=7')); $this->repository->purge(new Uri('app://self/collection/author-posts?author_id=8')); @@ -75,6 +77,18 @@ public function testHrefExpandingToAPathIsResolvedAndAnUnusableOneSkipped(): voi $this->assertNull($this->repository->get(new Uri($posts))); } + /** A row taken from the injector has no URI to resolve a path-only href against */ + public function testPathOnlyHrefOfARowWithoutUriPurgesNothing(): void + { + $posts = 'app://self/collection/posts'; + $this->resource->get($posts); + + $comment = $this->injector->getInstance(Comment::class); + $comment->onPut(1); + + $this->assertNotNull($this->repository->get(new Uri($posts))); + } + /** A write that moves a row to another list purges the old list with the value its body carries */ public function testMovePurgesTheOldListFromTheBody(): void { From 609a2833c6c6c0c6997ce35d0c64ab3196171eea Mon Sep 17 00:00:00 2001 From: Akihito Koriyama Date: Tue, 24 Nov 2026 10:16:15 +0900 Subject: [PATCH 4/5] Resolve a path-only collection href under app://self when the write has no URI A resource taken from the injector has no URI. Its path-only href purged nothing while an absolute one purged the list; the purge tag holds no scheme or host, so app://self reaches the same entries. --- src/RefreshAnnotatedCommand.php | 15 +++++++++------ tests/CollectionLinkTest.php | 6 +++--- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/RefreshAnnotatedCommand.php b/src/RefreshAnnotatedCommand.php index 086466f7..c4717f76 100644 --- a/src/RefreshAnnotatedCommand.php +++ b/src/RefreshAnnotatedCommand.php @@ -27,6 +27,7 @@ final readonly class RefreshAnnotatedCommand { private const COLLECTION = 'collection'; + private const ORIGIN_WITHOUT_URI = 'app://self'; public function __construct( private ResourceInterface $resource, @@ -124,18 +125,20 @@ private function uris(ResourceObject $ro, string $template, array $query): array return array_values(array_unique($uris)); } - /** A path-only href, as HAL writes it, is a resource path; the scheme and host are the write's */ + /** + * A path-only href, as HAL writes it, is a resource path under the write's scheme and host + * + * The purge tag holds no scheme or host, so a resource without a URI, taken from the injector, uses app://self. + */ private function resolved(string $href, AbstractUri|null $uri): string { - if ($uri === null) { - return $href; - } - if (! str_starts_with($href, '/') || str_starts_with($href, '//')) { return $href; } - return "{$uri->scheme}://{$uri->host}{$href}"; + $origin = $uri === null ? self::ORIGIN_WITHOUT_URI : "{$uri->scheme}://{$uri->host}"; + + return $origin . $href; } /** diff --git a/tests/CollectionLinkTest.php b/tests/CollectionLinkTest.php index 7177c5ce..d43cceba 100644 --- a/tests/CollectionLinkTest.php +++ b/tests/CollectionLinkTest.php @@ -77,8 +77,8 @@ public function testHrefExpandingToAPathIsResolvedAndAnUnusableOneSkipped(): voi $this->assertNull($this->repository->get(new Uri($posts))); } - /** A row taken from the injector has no URI to resolve a path-only href against */ - public function testPathOnlyHrefOfARowWithoutUriPurgesNothing(): void + /** A row taken from the injector has no URI, and its path-only href still purges the list */ + public function testPathOnlyHrefOfARowWithoutUriPurgesTheList(): void { $posts = 'app://self/collection/posts'; $this->resource->get($posts); @@ -86,7 +86,7 @@ public function testPathOnlyHrefOfARowWithoutUriPurgesNothing(): void $comment = $this->injector->getInstance(Comment::class); $comment->onPut(1); - $this->assertNotNull($this->repository->get(new Uri($posts))); + $this->assertNull($this->repository->get(new Uri($posts))); } /** A write that moves a row to another list purges the old list with the value its body carries */ From b668c836ff24a5246c6c094a4cc89795715f84de Mon Sep 17 00:00:00 2001 From: Akihito Koriyama Date: Tue, 24 Nov 2026 10:42:44 +0900 Subject: [PATCH 5/5] Resolve a path-only collection href as BEAR.Resource resolves a link UriFactory prefixes a schemeless href with the context scheme (#[ContextScheme]), as Linker does when it crawls the link, so the write's URI, or its absence, no longer decides the resolution. --- CHANGELOG.md | 2 +- docs/llms-full.txt | 2 +- src/RefreshAnnotatedCommand.php | 25 +++++-------------------- 3 files changed, 7 insertions(+), 22 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7fb16bca..9f3b442a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] ### Added -- `#[Link(rel: 'collection', href: ...)]` on a row's `onGet()` names the list it belongs to: a write to the row purges the list's URI and the variants that differ only in default-valued parameters, so the list needs no `#[DependsOn]` for its rows. A path-only href, as HAL writes it (`/posts`), names the list at that path. +- `#[Link(rel: 'collection', href: ...)]` on a row's `onGet()` names the list it belongs to: a write to the row purges the list's URI and the variants that differ only in default-valued parameters, so the list needs no `#[DependsOn]` for its rows. A path-only href (`/posts`) is resolved as BEAR.Resource resolves a link, under the context scheme (`#[ContextScheme]`). - The `purge_skipped` log entry (fields `uri`, the write's URI without its query, and `reason`, `unmatched_query`), recorded when a write on a resource without a cache attribute cannot address its own key because its query lacks a required `onGet()` parameter. - `AppSurrogateKeyModule($key)` adds the key to every entry this package stores and to every `Surrogate-Key` it sets, so invalidating the key on the server and at the CDN clears the whole application. Install it before or after `QueryRepositoryModule`. - `#[DependsOn(uri: ..., key: ...)]`: `key` names the rows in the body `onGet()` returns, so `#[DependsOn(uri: 'app://self/article?id={id}', key: 'articles')]` with `$this->body['articles'] = [['id' => 1, ...], ['id' => 2, ...]]` depends on `?id=1` and `?id=2`; a row that lacks the variable is skipped, an empty list names no URI, and a variable no row holds is read from the body's top level, then from the arguments. A body or row list that can be read only once, such as a `Generator`, is left in the body as an `ArrayIterator` with every row, under the keys it yielded unless a key repeats, as with `yield from`, which leaves a list. diff --git a/docs/llms-full.txt b/docs/llms-full.txt index 32fa8d9e..9112f090 100644 --- a/docs/llms-full.txt +++ b/docs/llms-full.txt @@ -143,7 +143,7 @@ class Article extends ResourceObject ``` - The purge reaches every variant of the collection that differs only in default-valued parameters (see Purging query variants): with `onGet(?int $authorId = null, int $page = 1)`, purging `app://self/articles` drops `?page=2` and `?author_id=7`. A list keyed by a required parameter, such as one author's articles, is another group: name it with `#[Purge]` on the write. -- The href expands as a `#[Purge]` template does, from the body the write returns, then from its query. An href that expands to a path, as HAL writes it (`/articles`), names the resource at that path, so one `#[Link]` serves both HAL and the purge; an href that does not expand to a resource URI and a `#[Link]` of another rel purge nothing. +- The href expands as a `#[Purge]` template does, from the body the write returns, then from its query. An href that expands to a path (`/articles`) is resolved as BEAR.Resource resolves a link, under the context scheme (`#[ContextScheme]`), so the purge and the link crawl name the same resource; an href that does not expand to a resource URI and a `#[Link]` of another rel purge nothing. - Which side declares the relation: when the list knows its rows and their number is bounded, declare `#[DependsOn]` on the list; when the row knows its list and the rows are unbounded, declare `#[Link(rel: 'collection')]` on the row. The collection link keeps the list to its own key. - A write that moves a row from one list to another names both lists with `#[Purge]`. The old value comes from the body the write returns, under a name other than the argument's, as the body is read before the query: diff --git a/src/RefreshAnnotatedCommand.php b/src/RefreshAnnotatedCommand.php index c4717f76..52b61a8f 100644 --- a/src/RefreshAnnotatedCommand.php +++ b/src/RefreshAnnotatedCommand.php @@ -12,6 +12,7 @@ use BEAR\Resource\ResourceInterface; use BEAR\Resource\ResourceObject; use BEAR\Resource\Uri; +use BEAR\Resource\UriFactory; use Ray\Aop\MethodInvocation; use ReflectionMethod; @@ -20,19 +21,18 @@ use function array_values; use function is_array; use function method_exists; -use function str_starts_with; use function uri_template; /** @internal */ final readonly class RefreshAnnotatedCommand { private const COLLECTION = 'collection'; - private const ORIGIN_WITHOUT_URI = 'app://self'; public function __construct( private ResourceInterface $resource, private CacheIdentityFactory $identityFactory, private DependsOnTemplates $templates, + private UriFactory $uriFactory, ) { } @@ -63,8 +63,7 @@ public function declared(MethodInvocation $invocation, ResourceObject $ro): arra $target = $invocation->getThis(); if ($target instanceof ResourceObject) { foreach ($this->collections($target) as $href) { - $expanded = array_map(fn (string $expandedHref): string => $this->resolved($expandedHref, $uri), $this->uris($ro, $href, $query)); - $declared[] = [$this->resourceUris($expanded), false]; + $declared[] = [$this->resourceUris($this->uris($ro, $href, $query)), false]; } } @@ -126,22 +125,8 @@ private function uris(ResourceObject $ro, string $template, array $query): array } /** - * A path-only href, as HAL writes it, is a resource path under the write's scheme and host + * Resolved as BEAR\Resource\Linker resolves a link, so a path-only href takes the context scheme (#[ContextScheme]) * - * The purge tag holds no scheme or host, so a resource without a URI, taken from the injector, uses app://self. - */ - private function resolved(string $href, AbstractUri|null $uri): string - { - if (! str_starts_with($href, '/') || str_starts_with($href, '//')) { - return $href; - } - - $origin = $uri === null ? self::ORIGIN_WITHOUT_URI : "{$uri->scheme}://{$uri->host}"; - - return $origin . $href; - } - - /** * @param list $uris * * @return list @@ -151,7 +136,7 @@ private function resourceUris(array $uris): array $resourceUris = []; foreach ($uris as $uri) { try { - $resourceUris[] = new Uri($uri); + $resourceUris[] = ($this->uriFactory)($uri); } catch (UriException) { continue; }