switon/binding
Composer 安装命令:
composer require switon/binding
包简介
Method argument lists and typed input hydration from rules and container state for Switon Framework
README 文档
README
Switon's binding layer for #[ResolvedBy] classes, action arguments, and typed input objects.
Highlights
- Declared resolution:
#[ResolvedBy]lets a class declare its resolver. - Action argument binding: parameters can come from events, resolvers, the container, or plain input.
- Typed input binding: arrays can become typed objects with validation and nested data support.
- Separate paths: scalar values and objects use separate binding flows.
- Resolution events: argument resolution emits its own lifecycle events.
Installation
composer require switon/binding
Quick Start
Binding starts with PageResolver.
use Switon\Binding\Attribute\ResolvedBy; use Switon\Orm\PageResolver; #[ResolvedBy(PageResolver::class)] class Page { protected int $page; protected int $limit; public static function of(int $page, int $limit = 10): static { $instance = new static(); $instance->page = max(1, $page); $instance->limit = max(1, $limit); return $instance; } }
use ReflectionParameter; use Switon\Core\Attribute\Autowired; use Switon\Binding\ValueResolverInterface; use Switon\Core\InputInterface; use Switon\Orm\Page; final class PageResolver implements ValueResolverInterface { #[Autowired] protected InputInterface $input; public function resolve(ReflectionParameter $parameter, string $type): mixed { return Page::of( (int) $this->input->get('page', 1), (int) $this->input->get('size', 10) ); } }
use Switon\Orm\Page; final class ArticleController { public function indexAction(Page $page): void { } }
Docs: https://docs.switon.dev/latest/binding
License
MIT.
统计信息
- 总下载量: 33
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 7
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-06-07