定制 switon/binding 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

switon/binding

Composer 安装命令:

composer require switon/binding

包简介

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

README 文档

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.

统计信息

  • 总下载量: 33
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 7
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-06-07

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固