pine3ree/pine3ree-params-resolver 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

pine3ree/pine3ree-params-resolver

最新稳定版本:1.0.1

Composer 安装命令:

composer require pine3ree/pine3ree-params-resolver

包简介

A function/method/invokable-object parameter resolution utility class

README 文档

README

Continuous Integration

ParamsResolver is an utility service that uses reflection to resolve parameters for a given callable performing look-up in the following order and matched against class/interface/parameter names:

  • injected parameters,
  • dependencies or parameters in the injected or composed container
  • default values if available in the callable parameters
// API (pseudo-code)

use My\Container;
use pine3ree\Container\ParamsResolver;

$params = new ParamsResolver($container);
$params->resolve($callable, array $resolvedParams);

// For a constructor the $callable argument would be:
$callable = [My\Class::class, '__construct'];

// or in general for any method:
$callable = [string $fqcn, string $methodName];

Example:

In the following example the $db and the $hydrator dependencies are fetched from the container, while the $config parameter is provided and the $options parameter receives the default empty array value.

<?php

use My\DataMapper;
use My\Db;
use My\Hydrator;
use pine3ree\Container\ParamsResolver;

class MyDataMapper
{
    private Db $db;
    private Hydrator $hydrator;
    private array $config;
    private array $options;

    public function__construct(
        Db $db,
        Hydrator $hydrator, 
        array $config,
        array $options = []
    ) {
        $this->db       = $db;
        $this->hydrator = $hydrator;
        $this->config   = $config;
        $this->options  = $options;
    }

    //... Rest of data-mapper code here
}

//...
// include the container building code/file
//...

$params = new ParamsResolver($container);

$args = $params->resolve([DataMapper::class, '__construct'], [
    'config' => [/*...*/], // a resolved value for the $config parameter
]);

$myDataMapper = new DataMapper(...args);

A common usage of ParamsResolver is within a reflection based factory like the following:

pine3ree/pine3ree-auto-resolve-factory

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2025-04-27