定制 stracker-phil/wpdi 二次开发

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

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

stracker-phil/wpdi

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

stracker-phil/wpdi 适用场景与选型建议

stracker-phil/wpdi 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 21 次下载、GitHub Stars 达 2, 最近一次更新时间为 2025 年 11 月 17 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「container」 「wordpress」 「di」 「dependency-injection」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 stracker-phil/wpdi 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 stracker-phil/wpdi 我们能提供哪些服务?
定制开发 / 二次开发

基于 stracker-phil/wpdi 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

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