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

Composer Repl Lib Laravel Package

ramsey/composer-repl-lib

Library for building interactive Composer-powered PHP REPLs. Provides the core loop and helpers to evaluate code in a Composer project context, load autoloaded classes, and inspect results—useful for CLI shells, debugging tools, and developer consoles.

View on GitHub
Deep Wiki
Context7

Getting Started

Start by installing ramsey/composer-repl-lib via Composer in your tool or plugin:

composer require ramsey/composer-repl-lib

Then, instantiate the REPL builder in your command logic (e.g., inside a Symfony Console or Laravel command):

use Ramsey\Composer\Repl\ReplBuilder;

$repl = (new ReplBuilder())
    ->withBootstrapFile('vendor/autoload.php')
    ->build();

$repl->start();

The first use case is typically spinning up a REPL inside a custom CLI command to inspect Composer-installed dependencies, test autoloaded classes, or debug configLoading logic interactively.

Implementation Patterns

  • Embed in custom CLI commands: Wrap the REPL in a Command::handle() method to offer developers a live environment without spawning a full shell.
  • Preload context: Use withVariable('name', $value) to inject application state (e.g., $app, config, or factory instances) into the REPL scope.
  • Customize evaluator: Implement EvaluatorInterface to tailor eval behavior (e.g., scope isolation, result formatting).
  • Laravel integration: In a service provider, bind the REPL as a shared service and fire it on demand via php artisan my:repl command.
  • Dynamic bootstrap: Generate on-the-fly bootstrap code (e.g., ->withBootstrapCode('$_env = $_ENV;')) to expose dynamic runtime state safely.

Gotchas and Tips

  • Security: Avoid passing eval()-untrusted input—this library is for developer tooling, not production use.
  • Autoload timing: Ensure vendor/autoload.php is included before the REPL starts—withBootstrapFile() assumes PSR-4/autoloading is ready.
  • CLI stream quirks: On Windows, verify php_sapi_name() === 'cli'; some REPL internals (e.g., readline) may silently fall back to basic input.
  • Silent eval: The REPL returns null for non-echoing expressions—use var_dump() or echo explicitly to inspect results.
  • Extensibility point: Extend Evaluator to add macro functions or hook into debug output (e.g., add Xdebug-style tracing).
  • No persistent state: Each start() invocation creates a fresh scope—store reusable snippets in ~/.composer-repl/config.php or your custom bootstrap.
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.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport