switon/binding

Method argument lists and typed input hydration from rules and container state for Switon Framework

Maintainers

Package info

github.com/switon-php/binding

Documentation

pkg:composer/switon/binding

Statistics

Installs: 32

Dependents: 7

Suggesters: 0

Stars: 0

Open Issues: 0

v1.0.0 2026-06-07 02:57 UTC

This package is auto-updated.

Last update: 2026-06-07 03:09:35 UTC


README

CI PHP 8.3+

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.