承接 blockify/container 相关项目开发

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

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

blockify/container

Composer 安装命令:

composer require blockify/container

包简介

Blockify container package.

README 文档

README

Simple PHP dependency injection container with autowiring for WordPress plugins and themes.

Installation

composer require blockify/container

Usage

PHP

First, require Composer's autoloader and then register the container:

require_once __DIR__ . '/vendor/autoload.php';

namespace MyNamespace;

use Blockify\Container\Container;
use Blockify\Container\Registerable;

$container = new Blockify\Container\Container();

$service_providers = [
	MyServiceProvider::class      => [ __FILE__ ],
	AnotherServiceProvider::class => [],
];

foreach ( $service_providers as $service_provider => $args ) {
	$instance = $container->make( $service_provider, ...$args );

	if ( $instance instanceof Registerable ) {
		$instance->register();
	}
}

Dependencies will be automatically resolved and injected into the constructor:

namespace MyNamespace;

class MyServiceProvider {

	private string $file;

	public function __construct( string $file ) {
		$this->dependency = $dependency;
	}
	
	public function getFile(): string {
		return $this->file;
	}
}

class AnotherServiceProvider implements Registerable {

	private MyServiceProvider $my_service_provider;

	public function __construct( MyServiceProvider $my_service_provider ) {
		$this->my_service_provider = $my_service_provider;
	}
	
	public function register() {
		echo $this->my_service_provider->getFile();
	}
}

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: GPL-2.0-or-later
  • 更新时间: 2024-04-24