d11wtq/boris
Interactive REPL for PHP powered by Boris. Drop into a console and inspect variables, evaluate code, explore objects, and debug applications quickly from the command line with an easy, lightweight shell.
Installation:
composer require d11wtq/boris --dev
Add to composer.json under require-dev to avoid production bloat.
First Run:
vendor/bin/boris
vendor/autoload.php and loads it.First Use Case:
// Inside Boris REPL:
$user = App\Models\User::first();
dd($user->toArray());
str()->slug('Hello World'); // Laravel's Str helper
$request = new \Illuminate\Http\Request();
$response = app()->handle($request);
Rapid Prototyping:
$data = ['name' => 'John', 'email' => 'john@example.com'];
$user = \App\Models\User::create($data);
$user->refresh(); // Verify DB state
Debugging Live Requests:
$response = \Illuminate\Support\Facades\Http::get('https://api.example.com/users');
$response->json();
Exploring Framework Internals:
app()->bindings(); // List all bound services
app()->make(\Illuminate\Contracts\Routing\UrlGenerator::class)->to('/');
Testing Artisan Commands:
$command = new \App\Console\Commands\GenerateReport();
$command->handle();
Bootstrap Laravel:
Run Boris from your project root to auto-load Laravel’s bootstrap/app.php:
vendor/bin/boris --bootstrap=bootstrap/app.php
$mailer = app(\Illuminate\Mail\Mailer::class);
Custom Aliases:
Add shortcuts to ~/.borisrc (if supported) or use PHP’s alias feature:
alias('u', 'App\Models\User::first()');
Persistent Sessions:
Use --persistent flag (if available) to retain variables between sessions:
vendor/bin/boris --persistent
Outdated Package:
psr/log, symfony/console) if compatibility issues arise.No Laravel-Specific Features:
tightenco/ziggy or laravel/ide-helper, Boris doesn’t natively integrate with Laravel’s helpers (e.g., route(), back(), asset()).helpers.php:
require app_path('Helpers.php');
Autoloader Conflicts:
vendor/autoload.php is loaded first.composer dump-autoload if classes aren’t found.Stateful Debugging:
\DB::transaction(function () {
$user = App\Models\User::find(1);
$user->update(['name' => 'Updated']);
});
get_defined_vars(); // List all variables in scope
error_reporting(E_ALL);
ini_set('display_errors', 1);
composer dump-autoload
php artisan optimize:clear
Custom Prompt:
Override the prompt in ~/.borisrc (if supported) or monkeypatch:
\Boris\Boris::getPromptFunction = function() { return 'laravel> '; };
Add Commands:
Extend Boris’s command system (if API allows) or use PHP’s register_shutdown_function to auto-load custom snippets.
Logging: Redirect output to a file for debugging:
vendor/bin/boris --log=boris.log
4. **Integration with Laravel Debugbar**:
Load Debugbar manually:
```php
$debugbar = new \Barryvdh\Debugbar\Debugbar();
$debugbar->addMessage('REPL Session');
```markdown
### Laravel-Specific Quirks
1. **Service Provider Bootstrapping**:
- If you need providers to load (e.g., `Hash`, `Cache`), manually boot them:
```php
$app = require_once __DIR__.'/bootstrap/app.php';
$app->boot();
```
2. **Environment Variables**:
- Load `.env` explicitly:
```php
$dotenv = new \Dotenv\Dotenv(__DIR__);
$dotenv->load();
```
3. **Queue Workers**:
- Test queue jobs interactively:
```php
$job = new \App\Jobs\SendEmail();
$job->handle();
```
4. **Event Listeners**:
- Dispatch and listen to events:
```php
event(new \App\Events\UserRegistered());
```
How can I help you explore Laravel packages today?