-
It feels like I'm missing a step, but how do you return the data from a ResourceTemplate? For example, let's say I have 'users'. So I would create: UserListResource And a UserResourceTemplate And then what? Where do I return the details for my users? I would expect I can return an array of users with basic information + id + perhaps the URI to the detailed info. But the ResourceTemplate doesn't contain a I feel like I should be able to implement a |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
I tried playing with https://symfony.com/doc/current/create_framework/routing.html public function read(string $uri): ?array
{
$resource = $this->resources[$uri] ?? null;
if ($resource) {
return $resource->read();
}
// Check the requested scheme
$scheme = uri($uri)->scheme();
try {
$routes = new \Symfony\Component\Routing\RouteCollection();
foreach($this->templates as $key => $template ) {
if (uri($template->uriTemplate)->scheme() === $scheme) {
$uriTemplate = Str::replaceFirst($scheme.'://', '/', $template->uriTemplate);
$routes->add($key, new \Symfony\Component\Routing\Route($uriTemplate));
}
}
if ($routes->count() === 0) {
return null;
}
$context = \Symfony\Component\Routing\RequestContext::fromUri($uri);
$matcher = new \Symfony\Component\Routing\Matcher\UrlMatcher($routes, $context);
$params = $matcher->match(Str::replaceFirst($scheme.'://', '/', $uri));
} catch (\Symfony\Component\Routing\Exception\ResourceNotFoundException $e) {
return null;
} catch (\Throwable $e) {
throw $e;
}
return $this->templates[$params['_route']]->read($params);
} And then you can call |
Beta Was this translation helpful? Give feedback.
-
@barryvdh Thank you for the feedback — I will look at it soon. |
Beta Was this translation helpful? Give feedback.
-
#35 done |
Beta Was this translation helpful? Give feedback.
#35 done