switon / binding
Method argument lists and typed input hydration from rules and container state for Switon Framework
v1.0.0
2026-06-07 02:57 UTC
Requires
- php: >=8.3
- psr/container: ^2.0
- psr/event-dispatcher: ^1.0
- switon/core: ^1.0
- switon/event: ^1.0
- switon/validation: ^1.0
Requires (Dev)
- phpstan/extension-installer: ^1.4
- phpstan/phpstan: ^2.0
- switon/testing: ^1.0
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.