Resource
URIに対応するリソースは、状態を決めて返す。
final class Profile extends ResourceObject
{
public function onGet(int $id): static
{
$this->body = $this->profileQuery->item($id);
return $this;
}
}Examples
BEAR.Sundayのコードは、リソースが中心です。入力、依存、リンク、横断的処理が見える場所に残るため、読み手はアプリケーションの意味をたどれます。
Resource
final class Profile extends ResourceObject
{
public function onGet(int $id): static
{
$this->body = $this->profileQuery->item($id);
return $this;
}
}Dependency Injection
public function __construct(
private readonly ProfileQuery $profileQuery,
private readonly ClockInterface $clock,
) {
}AOP
#[Transactional]
#[Cacheable(expirySecond: 30)]
public function onPost(string $name): static
{
$this->body = $this->command->create($name);
return $this;
}Hypermedia
#[Link(rel: 'orders', href: 'app://self/orders{?id}')]
#[Embed(rel: 'profile', src: 'app://self/profile{?id}')]
public function onGet(int $id): static
{
return $this;
}What this enables
リソースが状態を持ち、表現や転送は外側へ分かれる。依存は注入され、 横断的関心はAOPへ分かれる。この単純な分離が、テストと拡張の土台になります。
Start with one resource