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

Technical Evaluation

Architecture Fit

  • Lazy Loading Paradigm: Aligns perfectly with Laravel’s deferred execution patterns (e.g., Eloquent queries, collections). The LazyCollection design minimizes memory overhead during class/file discovery, critical for large codebases (e.g., monorepos, plugin systems).
  • PSR-4 Compliance: Leverages Laravel’s existing autoloading infrastructure (composer.json), reducing friction in namespace-aware applications. Avoids reinventing the wheel for class-to-path resolution.
  • Filtering Flexibility: Chainable methods (isInstanceOf(), hasTrait()) enable declarative discovery, mirroring Laravel’s query builder or collection APIs. Ideal for domain-specific logic (e.g., "register all queued commands in app/Jobs/").
  • Extensibility: Custom resolvers (resolvePathUsing, resolveClassnameUsing) allow adaptation to non-standard paths or custom autoloaders, supporting edge cases like vendor-agnostic plugins or multi-root projects.
  • Laravel-Centric: Deep integration with Laravel’s base_path(), app()->getNamespace(), and Finder components ensures seamless adoption in existing projects. Minimal abstraction overhead.

Integration Feasibility

  • Zero Configuration for 80% Use Cases: Works out-of-the-box with standard Laravel projects. Only requires composer require and basic usage (e.g., Lody::classes('app/Plugins')->each(...)).
  • Service Provider Hooks: Configuration (e.g., custom paths, autoload files) can be centralized in a single provider, adhering to Laravel’s container-first principles.
  • Backward Compatibility: Supports Laravel 11–13 and PHP 8.1+, with no breaking changes in recent releases. Downgrade path exists for older versions (e.g., Laravel 10 via v0.4.0).
  • Non-Laravel Support: Standalone mode (setBasePath()) enables use in Lumen, Symfony, or plain PHP, though Laravel-specific features (e.g., app()->getNamespace()) are lost.
  • Testing Integration: Lazy collections simplify test data generation (e.g., scan for DataFactory classes) and mocking (e.g., filter classes with hasMethod('mock')).

Technical Risk

Risk Area Severity Mitigation
Performance Overhead Low Lazy loading ensures minimal memory impact. Benchmark with ->count() before ->each().
PSR-4 Dependency Medium Custom resolvers can adapt to non-PSR-4 setups, but require upfront effort.
Laravel-Specific Logic Low Standalone mode exists, but loses Laravel conveniences (e.g., base_path()).
Class Validation Medium classExists() filters invalid classes, but runtime errors may occur if filters are too permissive.
Directory Traversal Low Uses Finder with recursive defaults; restrict paths explicitly (e.g., app/) to avoid vendor/ scans.
Trait/Method Reflection Low Relies on PHP’s ReflectionClass, which is stable but may miss edge cases (e.g., dynamic methods).
Future Laravel Breaking Changes Low Package maintains compatibility with latest Laravel versions (e.g., v0.7.0 for Laravel 13).

Key Questions for the Team

  1. Discovery Scope:
    • Should we scan only app/ or include vendor/ (e.g., for third-party plugins)? If the latter, how will we handle namespace collisions?
  2. Filtering Strategy:
    • What traits/interfaces should be used to identify classes for auto-registration? Example: ShouldAutoRegister, PluginContract.
    • Should filters be configurable per environment (e.g., disable hasTrait('DebugOnly') in production)?
  3. Performance:
    • Will lazy collections be used in high-frequency contexts (e.g., request middleware)? If so, cache results with ->remember() or ->cache().
    • For large directories (e.g., app/Modules/ with 1000+ classes), should we add parallel scanning or chunking?
  4. Error Handling:
    • How should invalid classes (e.g., syntax errors) be handled? Log and skip, or fail fast?
    • Should Lody integrate with Laravel’s exception handling (e.g., App\Exceptions\Handler)?
  5. Testing:
    • Will Lody be used to generate test data? If so, add a ->forTesting() method to exclude production-only classes.
    • Should we mock Lody in unit tests? Use a test double for Lody::classes() in critical paths.
  6. Maintenance:
    • Who will update the package if Laravel changes base_path() or Finder behavior?
    • Should we fork Lody to add custom features (e.g., database-backed discovery)?
  7. Security:
    • Are scanned directories writeable by untrusted users (e.g., plugin uploads)? If so, add path whitelisting.
    • Should we validate classnames against a allowlist (e.g., app/) to prevent vendor/ or node_modules/ scans?

Integration Approach

Stack Fit

  • Laravel Ecosystem: Optimized for Laravel’s service container, autoloading, and Finder components. Integrates natively with:
    • Service Providers: Register classes in boot() via Lody::classes()->each().
    • Facades: Dynamically bind facades to discovered classes (e.g., PluginManager::bind()).
    • Artisan Commands: Auto-discover commands implementing ShouldRegisterCommand.
    • Events: Register listeners with Lody::classes()->hasTrait('HandlesEvents').
  • PHP Extensions: Works with Symfony Finder, ReflectionClass, and SplFileInfo, ensuring compatibility with non-Laravel PHP.
  • Testing Tools: Compatible with Pest, PHPUnit, and Laravel Dusk for test data generation.

Migration Path

Phase Action Tools/Lody Methods
Assessment Audit existing manual registrations (e.g., register() in providers). Lody::classes('app/')->dump()
Pilot Replace one service provider with Lody (e.g., event listeners). Lody::classes('app/Listeners')->each(...)
Incremental Rollout Migrate plugins, commands, and policies in batches. Lody::files('app/Plugins')->getClassnames()
Full Adoption Replace all manual registrations with Lody. Lody::resolvePathUsing(fn($path) => ...)
Optimization Add caching (e.g., ->remember(60)) for performance-critical paths. Lody::classes()->cache()

Compatibility

  • Laravel Versions: Supports 11–13 (tested); downgrade to v0.4.0 for Laravel 10.
  • PHP Versions: Requires 8.1+ (for named arguments, attributes).
  • Composer: No conflicts with PSR-4 or classmap autoloading.
  • Windows: Explicitly tested (v0.3.0+).
  • Custom Autoloaders: Override resolveClassnameUsing for non-PSR-4 setups (e.g., App\ namespace mapped to src/).

Sequencing

  1. Core Integration:
    • Add lorisleiva/lody to composer.json.
    • Configure resolvers in AppServiceProvider (e.g., custom base path or classname logic).
  2. Pilot Feature:
    • Replace one manual registration (e.g., EventServiceProvider) with Lody.
    • Verify with tests: Lody::classes('app/Listeners')->count().
  3. Expand Scope:
    • Add plugins, commands, or policies to Lody’s discovery paths.
    • Example: Lody::classes('app/Plugins')->hasTrait('PluginContract')->each(...).
  4. Optimize:
    • Cache results for static paths (e.g., Lody::classes('app/Commands')->remember(3600)).
    • Add environment-specific filters (e.g., ->when(fn() => app()->isLocal(), ...)).
  5. Document:
    • Update contribution guidelines to specify Lody-compatible
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