lane4core/factory 问题修复 & 功能扩展

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

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

lane4core/factory

最新稳定版本:1.0.0

Composer 安装命令:

composer require lane4core/factory

包简介

The Factory class serves as a flexible instantiation and access factory for classes, supporting optional versioning and dependency injection (DI).

README 文档

README

Build Status

Purpose

The Factory serves as a flexible instantiation and access factory for classes, supporting optional versioning and dependency injection (DI).

Description for Developers

The class provides methods to dynamically create instances of classes or retrieve them from a provided container. It supports:

  • Class versioning through a ClassVersionInterface.
  • Dependency Injection via a Psr\Container\ContainerInterface.
  • Dynamic construction of classes with parameter support.

Notes

  • If a container is provided, the instance is retrieved from the container if available.
  • If no container is available or the class is not registered in the container, the instance is dynamically created using reflection.
  • Setting a container or ClassVersion is only possible once.

Usage

$factory = new Factory($container, $classVersion);
$instance = $factory->get(MyClass::class, '1.0', ['param1', 'param2']);

The class provides a central point for instantiation and management of objects with optional versioning and dependency injection.

Example code without classVersioning and without DI container

use lane4core\Factory\Factory;

$factory = new Factory();
$myClassInstance = $factory->get(MyClass::class);
$myClassInstance = $factory->get(MyClassWithTwoParameters::class, null, $var1, $var2);

Example code with classVersioning and without DI container

use lane4core\Factory\Factory;
use lane4core\Version\config\ClassVersionConfig;

$classVersions = ['subDirectory' => ['version1', 'version2']];
$classVersionConfig = new ClassVersionConfig($classVersions);
$classVersion = new ClassVersion($classVersionConfig);

$factory = new Factory(null, $classVersion);
$myClassInstance = $factory->get(MyClass::class);
$myClassInstance = $factory->get(MyClassWithTwoParameters::class, null, $var1, $var2);

Example code with classVersioning and DI container

use lane4core\Factory\Factory;
use lane4core\Version\config\ClassVersionConfig;

$container = new Container();
$classVersions = ['subDirectory' => ['version1', 'version2']];
$classVersionConfig = new ClassVersionConfig($classVersions);
$classVersion = new ClassVersion($classVersionConfig);

$factory = new Factory($container, $classVersion);
$myClassInstance = $factory->get(MyClass::class);
$myClassInstance = $factory->get(MyClassWithTwoParameters::class, null, $var1, $var2);

Quickstart Composer

composer require lane4core/factory
make install

Quickstart GitHub

git clone https://github.com/lane4core/factory.git
cd factory

Contents in the GitHub Repository

  • Source Files:
    • src
    • tests
  • Support:
    • Docker Compose
    • .env
    • pre-commit-hook.sh
    • Makefile Simply run make in the console
  • Documentation:
    • README.md

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-10-10