承接 ntentan/panie 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

ntentan/panie

最新稳定版本:v0.9.2

Composer 安装命令:

composer require ntentan/panie

包简介

A thin DI container for NtentanFX

README 文档

README

Tests Scrutinizer Code Quality Code Coverage Latest Stable Version Total Downloads

A PSR-Container compatible dependency injection container built for use in the ntentan framework. However, just like the other components in the framework, ntentan is not required for panie to work. Panie can be used as a dependency injection container in its own right.

Usage

To create an instance of the container we use:

<?php
require "vendor/autoload.php";
$container = new ntentan\panie\Container();
$fooInstance = $container->resolve(Foo::class);

Panie will create an instance of the Foo class and autowire the type hinted dependencies if our Foo class is defined as follows:

<?php
class Foo
{
    private $bar;

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

Configuring

In cases where we want to provide specific wiring, we can configure the container by providing with options to use when resolving class types.

As a example, in the case where our Foo class takes a BarInterface iterface and we specifically want the BarImplementation class, we can wire the container as follows:

<?php
require "vendor/autoload.php";
$container = new ntentan\panie\Container();
$container->bind(BarInterface::class)->to(BarImplementation::class);
$fooInstance = $container->get(Foo::class);

The container can also take a factory function that returns an instance of the required types.

<?php
require "vendor/autoload.php";
$container = new ntentan\panie\Container();
$container->bind(BarInterface::class)->to(function(){
    return new BarImplementation();
});

You can also make the container maintain an internal singleton of a particular service by specifying the singleton flag when binding types.

<?php
require "vendor/autoload.php";
$container = new ntentan\panie\Container();
$container->bind(BarInterface::class)->to(BarImplementation::class)->asSingleton();
$fooInstance = $container->get(Foo::class);

Apart from the bind and to functions, the container has a setup function that takes an associative array with wiring info for the container. In this case, a possible wiring could be ...

$container->setup([
    BarInterface::class => BarImplementation::class
]);

... or for singletons and factories ...

$container->setup([
    BarInterface::class => [function(){ ... }, 'singleton' => true]
]);

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-04-16

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固