encoredigitalgroup/laravel-discovery 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

encoredigitalgroup/laravel-discovery

Composer 安装命令:

composer require encoredigitalgroup/laravel-discovery

包简介

README 文档

README

A Laravel package that automatically discovers and caches interface implementations across your codebase and vendor packages.

Features

  • Interface Implementation Discovery: Automatically finds all classes that implement specific interfaces
  • Caching: Generates cached files for fast runtime lookups
  • Vendor Support: Can search through vendor packages for implementations
  • Configurable: Flexible configuration for search paths and interfaces
  • Artisan Command: Simple command to trigger discovery process

Requirements

  • PHP 8.3+
  • Laravel 11+

Installation

Install the package via Composer:

composer require encoredigitalgroup/laravel-discovery

The service provider will be automatically registered via Laravel's package auto-discovery.

Add the following to your post-autoload-dump script:

@php artisan discovery:run

This command will:

  1. Search for all configured interfaces
  2. Find implementing classes in your app, modules, and configured vendor paths
  3. Generate cache files in bootstrap/cache/discovery/

Usage

Basic Configuration

Configure the discovery system using the Discovery configuration class:

use EncoreDigitalGroup\LaravelDiscovery\Support\Discovery;

// Add interfaces to discover
Discovery::config()->addInterface(YourInterface::class);

// Add specific vendors to search
Discovery::config()
    ->addVendor("laravel")
    ->addVendor("spatie");

// Or search all vendors (extremely slow, use with caution)
Discovery::config()->searchAllVendors();

Retrieving Cached Results

Access the discovered implementations using the cache method:

use EncoreDigitalGroup\LaravelDiscovery\Support\Discovery;

// Get all implementations of an interface
$implementations = Discovery::cache(YourInterface::class);

Configuration Options

Search Paths

The package searches in the following directories by default:

  • app/ - Your application code
  • app_modules/ or app-modules/ - If they exist
  • Configured vendor directories (when enabled)

Cache Location

Cache files are stored in bootstrap/cache/discovery/ by default. Each interface gets its own cache file named after the interface (e.g., YourInterface.php).

Example

<?php

// Define an interface
interface PaymentGatewayInterface
{
    public function process(float $amount): bool;
}

// Implement the interface
class StripeGateway implements PaymentGatewayInterface
{
    public function process(float $amount): bool
    {
        // Implementation
    }
}

class PayPalGateway implements PaymentGatewayInterface
{
    public function process(float $amount): bool
    {
        // Implementation
    }
}

// Configure discovery
Discovery::config()->addInterface(PaymentGatewayInterface::class);

// Run discovery
// php artisan discovery:run

// Use the cached results
$gateways = Discovery::cache(PaymentGatewayInterface::class);
// Returns: ['App\\StripeGateway', 'App\\PayPalGateway']

How It Works

  1. Scanning: The package uses PHP-Parser to analyze PHP files and identify classes that implement specified interfaces
  2. Directory Traversal: Scans the following directories:
    • app/ - Your application code
    • app_modules/ or app-modules/ - Modular application code (if present)
    • Vendor directories (when configured)
  3. Caching: Generates PHP cache files in bootstrap/cache/discovery/ for each interface

Vendors and Interfaces are scanned/searched only once during Discovery

For example:

  • Package A configures Discovery to search for Interface 1.
  • Package B also configures Discovery to search for Interface 1.
  • Interface 1 will only be searched for once.
  • Interface 1 will be searched for in all locations configured by all packages.

Testing

Run the test suite:

composer test

License

This repository is licensed under a modified BSD-3-Clause License.

Contributing

Contributions are governed by the Encore Digital Group Contribution Terms.

encoredigitalgroup/laravel-discovery 适用场景与选型建议

encoredigitalgroup/laravel-discovery 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3.87k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 08 月 30 日, 在 PHP 生态内属于活跃度较高的组件。

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

围绕 encoredigitalgroup/laravel-discovery 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2025-08-30