定制 sefra/container 二次开发

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

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

sefra/container

最新稳定版本:v1.0.1

Composer 安装命令:

composer require sefra/container

包简介

service container for wordpress plugins and themes

README 文档

README

A lightweight service container for WordPress plugins and themes, inspired by Laravel's and other modern PHP frameworks’ dependency injection containers.
It allows you to bind classes, singletons, and closures, and automatically resolves dependencies via constructor injection.

Purpose

This container is a core part of the Sefra WordPress Plugin Starter Kit, providing dependency injection and service management for plugins.

Documentation

If you have a WordPress plugin and want to integrate Sefra Container to manage dependency injection, check this guide: How To Use Sefra Container

If you’re starting a new plugin, you might find this starter kit useful:

Installation

Use Composer to install:

composer require sefra/container

Usage

use Sefra\Core\Container;

// Get container instance
$container = Container::getInstance();

// Bind a class
$container->bind(App\Services\MyService::class);

// Bind a singleton
$container->singleton(App\Services\MySingletonService::class);

// Resolve an instance
$service = $container->get(App\Services\MyService::class);

Constructor Injection

Dependencies are automatically resolved:

class Logger {
    public function log($message) { /* ... */ }
}

class Mailer {
    public function __construct(Logger $logger) { $this->logger = $logger; }
}

$mailer = $container->resolve(Mailer::class); // Logger is injected automatically

Restrictions

Injecting the container itself into services is forbidden to prevent tight coupling.

Circular dependencies are detected and will throw an exception.

License

MIT

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-01-06

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固