定制 merophp/object-manager 二次开发

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

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

merophp/object-manager

最新稳定版本:0.1-beta

Composer 安装命令:

composer require merophp/object-manager

包简介

Object manager with dependency injection for the Merophp Framework

README 文档

README

Object manager with dependency injection for the Merophp Framework.

Installation

Via composer:

composer require merophp/object-manager

Basic Usage

require_once 'vendor/autoload.php';

use Merophp\ObjectManager\ObjectContainer;
use Merophp\ObjectManager\ObjectManager;

$oc = new ObjectContainer;
ObjectManager::setObjectContainer($oc);

$myInstance = ObjectManager::get(MyClass::class);

Dependency Injection

The object manager will scan the classes he has to instantiate for injection methods will use them to inject the dependencies.

require_once 'vendor/autoload.php';

use Merophp\ObjectManager\ObjectContainer;
use Merophp\ObjectManager\ObjectManager;

class Foo
{
    public Bar $bar = null;

    public function injectBar(Bar $bar)
    {
        $this->bar = $bar;
    }

    public function getBar()
    {
        return $this->bar;
    }
}

$myFooInstance = ObjectManager::get(Foo::class);
$myBarInstance = $myFooInstance->getBar();

By instantiating from class Foo the object manager will also instantiate the dependency Bar.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-12-22