- How do I install and register nette/robot-loader in a Laravel app?
- Install it with composer require nette/robot-loader, then bind a configured loader as a singleton in a service provider. Call addDirectory() for each scoped directory, setCacheDirectory() to an absolute writable path, and register() once during boot. The package ships no Laravel service provider or config file, so all wiring is yours.
- Can RobotLoader replace Composer's autoloader in Laravel?
- You should not replace Composer's autoloader; Laravel deployments rely on PSR-4 maps, optimized classmaps, and composer dump-autoload -o. Use RobotLoader only as a scoped discovery primitive for directories whose contents are unknown at build time, such as plugins, tenant modules, or generated code. Keep first-party application code on Composer to avoid duplicate-load and stale-index hazards.
- How do I configure the RobotLoader cache directory in Laravel?
- Call setCacheDirectory() with an absolute, writable path, typically somewhere under storage/framework or a dedicated cache directory. Older versions used setTempDirectory(), so check the installed major version. The directory must be writable in every target environment, including containers, and pre-warming it in the deploy pipeline avoids rebuilds on user requests.
- Does nette/robot-loader work with Laravel 10 or 11 and PHP 8.1?
- RobotLoader is framework-agnostic PHP, so Laravel 10 and 11 are fine as long as the PHP version is supported. Version 4.x requires PHP 8.1 or newer; if any target environment still runs PHP 8.0, pin to 3.4.x or plan an upgrade. There is no Laravel-specific package version to match.
- How do I autoload plugin or tenant module classes with RobotLoader in Laravel?
- Add each plugin or tenant directory with addDirectory(), point the loader at a persistent cache, and call register() once. RobotLoader scans those directories, indexes classes, interfaces, and traits, and refreshes the cache when source files change. This is the intended use case: dynamic directories that Composer cannot know about at build time.
- How do I test code that uses RobotLoader in Laravel?
- Point setCacheDirectory() at a temporary per-test directory and call refresh() so each test run sees the current files. Because lookups are case-sensitive since v3.0.0, include a test that references a class with different casing to catch macOS or Windows-only passes. Clean up the temp directory after the suite.
- Why does RobotLoader fail in read-only or ephemeral container environments?
- RobotLoader requires a writable cache directory to store its persistent index, so read-only filesystems or ephemeral containers can break the assumption that it can rebuild. Pre-warm the cache during the build or deploy step and mount a writable path if the loader must refresh. Also decide whether a parse error should fail boot or only the affected feature, because reportParseErrors can widen the blast radius.
- What license does nette/robot-loader use?
- Composer metadata reports the license as NOASSERTION, even though Nette packages are typically BSD-3-Clause. Get legal sign-off before shipping it in a commercial or SaaS product rather than assuming the license. This is a hard checklist item, not a background task.
- What are alternatives to nette/robot-loader for class discovery in Laravel?
- Composer classmaps and Laravel's built-in command and event discovery already cover many cases. For dynamic directories, alternatives include Symfony Finder with reflection or your own manifest generator, but you lose RobotLoader's persistent cache and atomic cache writes. RobotLoader remains a focused choice when you need repeatable directory scanning with invalidation.
- Is nette/robot-loader actively maintained and safe to depend on?
- It is maintained within the Nette ecosystem and used by respected projects such as PHPStan, but it has a narrow consumer base with roughly 889 stars and no listed dependents. Expect to own integration problems yourself rather than find them answered upstream. Keep the API surface small so you can vendor a fork if the package is abandoned.