The Rhapsody Console (CLI)
Rhapsody includes a powerful command-line interface built on the Symfony Console component. It is the primary tool for interacting with your application outside of the web browser, allowing you to automate tasks, generate boilerplate code, and manage your application's state.
The CLI is accessed via the rhapsody executable file in your project root.
Listing Commands
To see a list of all available commands, simply run the application without any arguments. This will display a list of commands along with their descriptions.
php rhapsody
Code Generation (`make:*`)
The console includes a suite of generator commands to quickly create new classes for your application. These commands create "stub" files in the correct directories, complete with the correct namespaces, base classes, and essential methods.
Creating a Controller
This command creates a new controller file in the app/Controllers directory.
php rhapsody make:controller OrderController
This will generate app/Controllers/OrderController.php.
Creating a Model
This command creates a new model file in the app/Models directory.
php rhapsody make:model Order
This will generate app/Models/Order.php.
Creating Middleware
This command creates a new middleware file in the app/Middleware directory.
php rhapsody make:middleware CheckSubscriptionStatus
This will generate app/Middleware/CheckSubscriptionStatusMiddleware.php.
Database Migrations
Migrations are like version control for your database. Rhapsody uses Phinx, managed through the console, to handle schema changes reliably across all development and production environments.
Creating a Migration
This command will create a new, timestamped migration file in the db/migrations directory. Use a descriptive name that explains what the migration does.
php rhapsody make:migration CreateProductsTable
Running Migrations
To apply all pending migrations and update your database schema to the latest version, run the migrate command.
php rhapsody migrate
Caching
Rhapsody provides caching mechanisms to improve your application's performance in production. The console provides commands to manage these caches.
Twig Cache Warmup
After clearing caches (or after a fresh deployment), the first visitor to a page may experience a slight delay because Twig compiles templates on the fly. To avoid this, you can pre‑compile all templates using the cache warmer.
php rhapsody app:cache-warm
The command scans both your active theme and the default theme, compiles every .twig file into the Twig cache directory. Subsequent requests will serve the pre‑compiled templates immediately.
By default, the command uses the direct compilation method. An alternative crawl method (which hits actual URLs) is also available for warming other caches (Doctrine, routes) – use --method=crawl --base-url=https://yourdomain.com if needed.
Route Caching
For a significant performance boost, you can compile all of your application's route definitions into a single, cached file.
# Generate the route cache file
php rhapsody route:cache
# Remove the route cache file (necessary after changing routes)
php rhapsody route:clear
Important: You must clear and re-cache your routes whenever you make a change to your routes/web.php or routes/api.php files.
route:cache command will fail if any of your routes use a closure as the callback. Always use controller/action pairs when you plan to cache routes.
Application Cache
This command will flush the entire application data cache, which is used by the Rhapsody\Core\Cache service.
php rhapsody cache:clear
This is useful during development when you've changed the underlying data that an expensive, cached operation depends on.