BowPHP Console
Introductionβ
The BowPHP console is a powerful tool that helps you speed up your development. It provides a set of handy commands to generate classes, test your application locally, manage your databases, and much more.
All commands are run from the root of your application using the syntax: php bow <command>
Generation commandsβ
These commands help you quickly create the building blocks of your application:
| Command | Description |
|---|---|
generate:resource | Creates a complete REST controller. Example: php bow generate:resource UserController |
generate:key | Generates a new security key for the application |
generate:session-table | Creates a migration for the sessions table |
generate:notification-table | Creates a migration for the notifications table |
generate:cache-table | Creates a migration for the cache table |
generate:queue-table | Creates a migration for the queues table |
gen is the alias for generate (and not for add). The examples above
can therefore be written as:
php bow gen:resource UserController
php bow gen:key
Adding componentsβ
These commands let you quickly add components to your application:
Controllers and Middlewareβ
| Command | Description |
|---|---|
add:controller | Creates a new controller. Example: php bow add:controller OrderController |
add:middleware | Creates a new middleware. Example: php bow add:middleware AuthMiddleware |
Models and Databaseβ
| Command | Description |
|---|---|
add:model | Creates a new model. Example: php bow add:model Product |
add:migration | Creates a new migration. Example: php bow add:migration create_orders_table |
add:seeder | Creates a seeding file. Example: php bow add:seeder UsersSeeder |
add:validation | Creates a new validator. Example: php bow add:validation UserValidation |
Services and Configurationβ
| Command | Description |
|---|---|
add:service | Creates a new service. Example: php bow add:service PaymentService |
add:configuration | Creates a configuration file. Example: php bow add:configuration payment |
add:exception | Creates a new exception. Example: php bow add:exception InvalidUserException |
Events and Notificationsβ
| Command | Description |
|---|---|
add:event | Creates a new event. Example: php bow add:event UserRegisteredEvent |
add:listener | Creates an event listener. Example: php bow add:listener UserRegisteredListener |
add:notifier | Creates a new notifier. Example: php bow add:notifier EmailNotifier |
Queue and Tasksβ
| Command | Description |
|---|---|
add:task | Creates a new queued task. Example: php bow add:task SendInvoiceTask |
add:scheduler | Creates a scheduled task (scheduler). Example: php bow add:scheduler CleanupScheduler |
add:command | Creates a custom console command. Example: php bow add:command ImportDataCommand |
Migrationsβ
Migrations make it easy to manage the evolution of your databases:
| Command | Description |
|---|---|
migrate | Applies all pending migrations |
migration:migrate | Alias for migrate |
migration:rollback | Rolls back the last migration |
migration:reset | Resets all migrations |
The migration:reset command deletes all data. Use it carefully in production.
Seedingβ
Seeding lets you initialize your database with data:
| Command | Description |
|---|---|
seed:all | Runs all seeders |
seed:file [class] | Runs a specific seeder. Example: php bow seed:file UsersSeeder |
Queue Workerβ
Manage your queued jobs:
| Command | Description |
|---|---|
run:worker | Starts the worker to process jobs |
flush:worker | Empties the queue (use with caution) |
Available options for run:worker:
--connection: Connection to use (beanstalkd,sqs,redis,database)--queue: Queue name (default:default)--tries: Maximum number of attempts per job--timeout: Timeout in seconds per job--sleep: Pause between jobs in seconds
php bow run:worker --queue=emails --tries=5
Schedulerβ
Manage scheduled tasks. The verb is schedule (singular), and there are
five actions:
| Command | Description |
|---|---|
schedule:run | Runs the due tasks once (ideal for a cron running every minute) |
schedule:work | Runs the scheduler in daemon mode (continuous loop) |
schedule:list | Lists all registered tasks |
schedule:next | Displays the next run time for each task |
schedule:test [class] | Runs a specific task for testing |
# Run once (for cron)
php bow schedule:run
# Daemon mode (runs continuously in a loop)
php bow schedule:work
# View
php bow schedule:list
php bow schedule:next
# Test a task by class name
php bow schedule:test App\\Tasks\\CleanupTask
Clearing the cacheβ
These commands let you reset the caches:
| Command | Description |
|---|---|
clear:view | Deletes the compiled views cache |
clear:cache | Deletes the general cache |
clear:session | Deletes the sessions cache |
clear:log | Deletes the log files |
clear:all | Deletes all caches |
Development serverβ
| Command | Description |
|---|---|
run:server | Starts a local web server |
run:console | Starts an interactive console (REPL) |
# Server on the default port (8080)
php bow run:server
# Server on a custom port
php bow run:server --port=3000
# Interactive console
php bow run:console
Creating a custom commandβ
1. Generate the classβ
php bow add:command SendReportCommand
This command creates a file at app/Commands/SendReportCommand.php:
<?php
namespace App\Commands;
use Bow\Console\AbstractCommand;
use Bow\Console\Color;
class SendReportCommand extends AbstractCommand
{
/**
* Method called when the command is invoked. The first argument is
* the raw name of the command as typed by the user.
*/
public function process(): void
{
echo Color::green("Rapport envoyé avec succès !\n");
}
}
For a class registered as a command, Bow calls the process() method.
You can also register a closure (see below) β in that case it
receives (Argument $arg, Setting $setting).
2. Register the commandβ
Registration is done via Console::register() (static) or
$console->addCommand() (instance). Both methods accept up to
four arguments:
use Bow\Console\Console;
use App\Commands\SendReportCommand;
Console::register(
'send:report', // Name used on the command line
SendReportCommand::class, // Class or closure
'Envoie le rapport quotidien', // Description (shown in `php bow help`)
"\nUsage:\n php bow send:report [--to=...]\n" // Help shown by `php bow send:report help`
);
You can place these calls in a dedicated bootstrap file (declared in
Setting::getBootstrap()), or in the run() method of a service provider
(Bow\Configuration\Configuration).
3. Runβ
# Run the command
php bow send:report
# View its help
php bow send:report help
# The command also appears in the "CUSTOM" section of the global help
php bow help
For simple commands you can register a closure directly:
Console::register('hello', function ($arg, $setting) {
echo "Hello, " . ($arg->getTarget() ?? 'world') . "\n";
});
Is something missing?
If you run into problems with the documentation or have suggestions to improve the documentation or the project in general, please open an issue for us, or send a tweet mentioning the Twitter account @bowframework or directly on github.