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

🗄 Load files and classes as lazy collections in Laravel.

Frequently asked questions about Lody
How do I lazy-load all non-abstract classes in a Laravel directory (e.g., app/Commands) without memory issues?
Use `Lody::classes('app/Commands')->isNotAbstract()` to create a lazy collection. This defers file scanning until iteration, avoiding memory spikes during bootstrapping. Ideal for directories with thousands of classes.
Can Lody scan classes in the vendor/ directory for plugin systems or third-party integrations?
Yes, explicitly target vendor paths with `Lody::classes('vendor')`. To avoid scanning unintended libraries, whitelist paths using `resolvePathUsing` or filter by namespace (e.g., `isInstanceOf(PluginInterface::class)`).
Does Lody work with Laravel 13, or is it limited to older versions?
Lody supports Laravel 11–13 and PHP 8.1+. It’s tested against LTS releases (e.g., 11.x, 12.x) and maintains backward compatibility. No breaking changes in recent updates.
How do I customize classname resolution for non-PSR-4 projects (e.g., custom autoloaders or monorepos)?
Override `resolveClassnameUsing` in a service provider to handle custom logic. For example, use `class_exists()` checks or regex patterns to map filenames to classnames outside PSR-4 conventions.
Is there a performance difference between Lody and manually using glob() + ReflectionClass for class discovery?
Lody’s lazy evaluation ensures O(1) memory usage during discovery, while glob() loads all files into memory upfront. For directories with >5K classes, Lody is significantly more efficient. Pre-filter by namespace (e.g., `app/Plugins/*`) for further optimization.
How do I handle errors if a class file is deleted or invalid during iteration?
By default, Lody skips invalid classes. To enforce stricter checks, wrap iteration in a `try-catch` or use `class_exists()` filters. For logging, extend the `each()` callback to handle exceptions.
Can I use Lody to register service providers dynamically at runtime?
Yes. Chain `Lody::classes('app/Providers')->isInstanceOf(ServiceProvider::class)->each(fn($class) => $this->app->register($class))` to auto-discover and register providers without manual entries in `config/app.php`.
Does Lody support cross-platform path handling (Windows/Linux/macOS)?
Yes. Lody uses Laravel’s `Str::` helpers and `DIRECTORY_SEPARATOR` for cross-platform compatibility. Tested on all major OSes; no path-specific issues reported in production.
How can I exclude certain directories (e.g., storage/, tests/) from class scanning?
Use the `resolvePathUsing` resolver to validate paths against `base_path()` and exclude sensitive directories. Example: `return Str::contains($path, ['storage', 'tests']) ? null : base_path($path);`.
Are there alternatives to Lody for lazy class discovery in Laravel?
For basic use cases, you could use `glob()` + `ReflectionClass`, but Lody integrates deeper with Laravel’s ecosystem (e.g., `LazyCollection`, PSR-4, and `Finder`). For plugin systems, consider `spatie/laravel-package-tools`, but Lody offers more flexibility for custom resolvers and filtering.
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.
nexmo/api-specification
capell-app/block-library
axium/identity
cetria/laravel-dummy-models
cetria/reflection-helper
agropredict/sso-auth-bundle
evolvestudio/spam-protection
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
ecotone/kafka
22h/doctrine-garbage-collection-bundle
agtp/agtp-php
agtp/mod-php
splash/sonata-admin
splash/metadata