定制 pine3ree/pine3ree-generic-factories 二次开发

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

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

pine3ree/pine3ree-generic-factories

最新稳定版本:0.9.0

Composer 安装命令:

composer require pine3ree/pine3ree-generic-factories

包简介

Abstract factories based on reflection and configuration

README 文档

README

Continuous Integration

This package provides a reflection-based factory, which is based on the pine3ree-params-resolver package and a configuration-based factory with dependencies specified inside configuration

Example for reflection-based factory:

<?php

use My\App\Model\PostMapper;
use Psr\Container\ContainerInterface;
use pine3ree\Container\Factory\ReflectionBasedFactory;

$container = include("config/container.php");
$factory = new ReflectionBasedFactory(); // Need just one instance

// All dependencies of PostMapper are resolved by the factory if found in the
// container
$postMapper = $factory($container, PostMapper::class);

Example for configuration-based factory:

<?php

use My\App\Model\Database\Db;
use My\App\Model\Database\PdoFactory;
use My\App\Model\PostMapper;
use PDO;
use Psr\Container\ContainerInterface;
use pine3ree\Container\Factory\ConfigurationBasedFactory;

$container = include("config/container.php");
$factory = new ReflectionBasedFactory(); // Need just one instance

$config = $container->get('config');
// The 'config' service in the container should return an array like the
// one below:
$config = [
    //...
    'dependencies' => [
        'factories' => [
            //...
            PDO::class => PdoFactory::class, // Ad-hoc factory
            //...
        ],
        // Configuration key for dependencies built by the config-based factory
        ConfigurationBasedFactory:class => [
            // Just list the dependencies class names or container service-ids
            // for each managed class
            Db::class => [
                PDO::class, // Resolved by a custom factory
            ],
            PostMapper::class => [
                Db::class, // Resolved by the config-based factory as well
                'config', // THe 'config' array will be injected as 2nd argument
            ],
        ],
    ],
    //...
];

$postMapper = $factory($container, PostMapper::class);

统计信息

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

GitHub 信息

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

其他信息

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