承接 stracker-phil/wpdi 相关项目开发

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

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

stracker-phil/wpdi

最新稳定版本:1.2.0

Composer 安装命令:

composer require stracker-phil/wpdi

包简介

Truly WordPress-native dependency injection

README 文档

README

Ask DeepWiki

WPDI - WordPress Dependency Injection

Lightweight, WordPress-native dependency injection with auto-discovery and zero configuration.

Features

  • Zero Config - Autowires concrete classes in src/ folder
  • Production Ready - Cached class mapping; only modified files re-scanned during development
  • WordPress Native - Follows WordPress coding standards
  • PSR-11 Compatible - Standard container interface
  • Opinionated - Limited feature-set by design

Philosophy

"Constraint is the feature"

In my experience, DI usually fails in WordPress projects not because they lack features, but because they have too many. It's easy for developers to misuse the container as a global registry, a configuration store, a service locator - all patterns that DI was meant to solve.

WPDI prevents these patterns by design. It does one thing well: wire your classes together automatically. Everything else—configuration, state, WordPress options—stays where it belongs.

Quick Start

<?php
/**
 * Plugin Name: My Plugin
 */

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

class My_Plugin extends WPDI\Scope {
    protected function bootstrap( WPDI\Resolver $r ): void {
        $app = $r->get( My_Application::class );
        $app->run();
    }
}

My_Plugin::boot( __FILE__ );

Your classes in src/ are auto-discovered and autowired:

<?php
// src/My_Application.php

class My_Application {
    public function __construct( My_Service $service, My_Logger $logger ) {
        $this->service = $service;
        $this->logger = $logger;
    }

    public function run(): void {
        add_action( 'init', array( $this, 'on_init' ) );
    }
}

Configuration (Optional)

For interface bindings or classes outside src/ (e.g., Composer packages), create wpdi-config.php:

<?php
// Very basic example. Read the "Configuration" doc for more options.
return array(
    Logger_Interface::class => WP_Logger:class,
    Cache_Interface::class  => Redis_Cache::class,
);

Caching

Autowiring uses reflection to analyze constructor dependencies—but only once. WPDI caches the class mapping and rebuilds it automatically when files change. In production, this means zero overhead: just a single array lookup per service.

For deployment, pre-compile the cache to avoid the initial scan:

wp di compile

Requirements

  • PHP 7.4+
  • WordPress 5.0+

Documentation

Tip: Use DeepWiki to explore the codebase using AI - https://deepwiki.com/stracker-phil/wpdi

License

GPL-2.0

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: GPL-2.0
  • 更新时间: 2025-11-17

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固