Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Lody Laravel Package

lorisleiva/lody

Lody loads files or PHP classes from one or more paths as a Laravel LazyCollection. Discover classes via PSR-4 resolution, then filter (e.g., non-abstract, instance of) and iterate to register or process them. Configurable path and classname resolving.

View on GitHub
Deep Wiki
Context7

Product Decisions This Supports

  • Plugin/Extension Ecosystem: Enable a marketplace-like architecture where third-party or internal developers drop classes into directories (e.g., app/Plugins/Payment/), and Lody auto-discovers and registers them based on traits/interfaces (e.g., PaymentGateway). This reduces onboarding friction and accelerates feature delivery for SaaS platforms, CMS, or internal tools.
  • Reduced Technical Debt: Eliminate repetitive register() calls in service providers for classes like EventListeners, Policies, or Rules. By scanning directories and filtering via traits/methods (e.g., hasTrait('ShouldQueue')), teams avoid manual updates when adding new classes, scaling effortlessly.
  • Dynamic Feature Flags: Combine Lody with Laravel’s config system to conditionally load classes (e.g., hasTrait('Serializable')->when(fn() => config('features.enabled'))). This supports gradual rollouts, A/B testing, or tenant-specific configurations without refactoring core logic.
  • Test Automation: Scan for classes with methods like generateTestData() or mock() to automate test setup, improving CI/CD efficiency and test coverage. Reduces flaky tests by ensuring consistent, dynamic test data pipelines.
  • CLI Tooling: Dynamically register Artisan commands implementing traits (e.g., QueuedCommand) to build self-documenting CLI tools that adapt to new requirements. Ideal for admin panels, developer tools, or internal automation.
  • Legacy Modernization: Bridge legacy systems by scanning for classes with specific signatures (e.g., hasMethod('legacyProcess')) and wrapping them in modern interfaces (e.g., Processable). Lowers migration risk by incrementally adopting new patterns.
  • Domain-Driven Design (DDD): Discover and instantiate domain-specific classes (e.g., app/Domain/Users/Commands/) to enforce consistent patterns across repositories, services, and use cases. Supports bounded contexts in large applications.
  • Roadmap Priorities:
    • Plugin Marketplace: Build an internal or external plugin system where developers drop classes into directories (e.g., plugins/payment-stripe/src/) and Lody auto-registers them.
    • Dynamic Configuration: Load configurations from classes implementing Configurable to support runtime overrides (e.g., config('services.'.classname)).
    • Performance Optimization: Use lazy collections to avoid memory spikes during class discovery in large monorepos or microservices.

When to Consider This Package

Adopt When:

  • You need PSR-4 compliant class discovery with lazy-loaded filtering (e.g., by traits, inheritance, or methods) in Laravel 11–13.
  • Your project requires auto-registration of classes (e.g., for workflows, plugins, or event listeners) to reduce boilerplate and improve scalability.
  • You’re building a modular architecture where components should be conditionally loaded based on runtime conditions (e.g., environment, feature flags).
  • You want to eliminate manual class registration in service providers, facades, or configuration files, reducing errors and cognitive load.
  • Your stack includes Laravel 11–13 and PHP 8.1+, and you prefer a lightweight, MIT-licensed solution with active maintenance.
  • You need to scan vendor/ or custom directories for classes implementing specific interfaces (e.g., PaymentGateway, AuthProvider).
  • You’re working with complex directory structures and require filtering classes based on traits, methods, or inheritance hierarchies.
  • You need lazy-loaded collections to avoid memory overhead from eager-loading all classes/files upfront (e.g., in large codebases).
  • You’re integrating third-party libraries and need to dynamically discover their classes (e.g., scanning vendor/ for implementations of custom interfaces).

Look Elsewhere When:

  • You need cross-language support (e.g., Python, Node.js) or non-PHP file operations (use language-specific tools).
  • Your project uses non-PSR-4 class naming conventions (e.g., custom autoloaders). Override resolveClassnameUsing, but expect additional maintenance.
  • You’re targeting Laravel <11 or PHP <8.1. Use lower-level tools like SplFileInfo, ReflectionClass, or get_declared_classes().
  • You require vendor-agnostic class discovery beyond PSR-4 (e.g., for Symfony or custom autoloaders). Combine with class_alias() or get_declared_classes().
  • You need database-backed or remote class discovery (e.g., for distributed systems). Use service discovery tools (e.g., Consul, etcd).
  • You’re working in a non-Laravel PHP environment (e.g., Lumen, Symfony). Use standalone mode with setBasePath() or adapt the logic.
  • You require real-time file watching (e.g., for development tools). Use Laravel Mix, Vite, or custom spl_file_info observers.

How to Pitch It (Stakeholders)

For Executives:

*"Lody is a developer productivity multiplier for Laravel projects. It automates the discovery and registration of classes—like plugins, workflow nodes, or event listeners—so teams can build modular, extensible systems without manual configuration. For example:

  • Reduce onboarding time for third-party plugins by 50%: Developers drop a class into app/Plugins/ and Lody auto-registers it if it implements PaymentGateway.
  • Cut technical debt by eliminating repetitive register() calls in service providers, freeing engineers to focus on features.
  • Accelerate feature flags: Dynamically load classes only when enabled, supporting A/B tests or tenant-specific configurations without refactoring.
  • Improve test reliability: Auto-generate test data from classes with generateTestData(), reducing flaky tests in CI/CD pipelines.

This is a low-risk, high-reward investment for teams scaling Laravel applications, with no vendor lock-in (MIT license) and minimal maintenance overhead."*


For Engineering Teams:

*"Lody solves the ‘where do I register this?’ problem in Laravel. Instead of manually adding classes to service providers, facades, or config files, you:

  1. Drop a class into a directory (e.g., app/Workflow/Nodes/).
  2. Filter it dynamically (e.g., Lody::classes('app/Workflow/Nodes')->isInstanceOf(Node::class)->each(...)).
  3. Let Lody handle the rest—no more forgotten registrations or merge conflicts.

Key benefits:

  • Lazy loading: Avoid memory spikes by processing classes on-demand (critical for large codebases).
  • Flexible filtering: Use traits (hasTrait('ShouldQueue')), inheritance (isInstanceOf(PaymentGateway::class)), or methods (hasMethod('execute')) to fine-tune discovery.
  • Works with vendor classes: Respects PSR-4 autoloading, so it can even scan vendor/ for third-party implementations.
  • Integrates with Laravel: Plays nicely with base_path(), app_path(), and Laravel’s config system for conditional loading.

Use cases we’ve validated:

  • Auto-registering event listeners, policies, or rules in service providers.
  • Building plugin systems (e.g., payment gateways, auth providers) with zero boilerplate.
  • Dynamically loading test data generators or mock factories.
  • Modernizing legacy code by wrapping old classes in new interfaces.

Getting started is trivial:

composer require lorisleiva/lody

Then replace manual registrations like this:

// Before (manual)
$this->app->bind('payment.stripe', StripeGateway::class);

// After (dynamic)
Lody::classes('app/Gateways/Payment')
    ->isInstanceOf(PaymentGateway::class)
    ->each(fn(string $class) => $this->app->bind('payment.'.$class, $class));

No breaking changes, just less busywork."*


For Developers:

*"Lody is your Swiss Army knife for class discovery in Laravel. Need to find all classes in a directory that implement an interface? Filter by trait? Check for a specific method? Done in one line:

Lody::classes('app/Commands')
    ->hasTrait('QueuedCommand')
    ->each(fn(string $class) => Artisan::register($class));

Why you’ll love it:

  • Lazy collections: No more scandir() + ReflectionClass hell. Lody processes files/classes on-demand, saving memory.
  • PSR-4 aware: Respects your composer.json autoloading, so it works out of the box—even for vendor classes.
  • Customizable: Override path resolution, classname generation, or filtering logic to fit your needs.
  • Laravel-native: Uses base_path(), app_path(), and integrates with Laravel’s service container.

Pro tip: Combine with when() to load classes conditionally:

Lody::classes('app/Features')
    ->hasMethod('isEnabled')
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament
leek/filament-subtenant-scope