Download the PHP package danilovl/web-command-bundle without Composer
On this page you can find all versions of the php package danilovl/web-command-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download danilovl/web-command-bundle
More information about danilovl/web-command-bundle
Files in danilovl/web-command-bundle
Package web-command-bundle
Short Description A Symfony bundle for running console commands via web interface
License MIT
Informations about the package web-command-bundle
WebCommandBundle
A Symfony bundle for running console commands via web interface (REST API). Supports both synchronous and asynchronous (via Messenger) execution.
Features
- REST API for listing and running commands.
- Support for asynchronous command execution using Symfony Messenger.
- Configurable API prefix, console path, memory and time limits.
- Entity-based management for commands, jobs and history.
- EasyAdmin integration for managing commands and viewing history.
- Flexible command configuration (voters, async, history, parameters, etc.).
- Automatic PHP binary detection.
Available dashboard
Installation
-
Install the bundle via composer:
-
Add the bundle to
config/bundles.php: -
Import routes in
config/routing.yaml(routing is not automatic): - Doctrine entity mapping
Add entity mapping to doctrine.yaml in packages folder.
- Update your database schema:
Configuration
Create config/packages/web_command.yaml:
Note:
console_path: ifnull(default), it's%kernel.project_dir%/bin/console. If set, it's used as is (absolute path).default_timeout,default_time_limitanddefault_memory_limitarenullby default.default_timeout: default timeout (seconds) for synchronous command execution via API.default_time_limit: default timeout (seconds) for asynchronous command execution.default_memory_limit: applied via-d memory_limit=...during process execution.enabled_admin_dashboard: enable EasyAdmin dashboard integration.enabled_dashboard_live_status: enable/disable interval requests to check job status on the web dashboard.
Messenger Configuration
To enable asynchronous execution, configure Symfony Messenger:
Usage
REST API
The bundle provides a REST API to interact with commands. By default, the API is available under the /danilovl/web-command/api prefix.
Admin Interface
The bundle includes a built-in EasyAdmin dashboard for managing commands and viewing execution history.
To use it, ensure you have EasyAdminBundle installed and configured, and enable it in the configuration:
The dashboard is available at /admin/danilovl/web-command.
The admin interface allows you to:
- Create, update, and delete commands.
- View execution history and command outputs.
Web Dashboard
The bundle also provides a standalone web dashboard to run commands and view their history.
The dashboard is available at /danilovl/web-command/dashboard.
Route Name: danilovl_web_command_dashboard_index
Features:
- List of active commands.
- Input for additional parameters.
- Formatted output display.
- History of recent executions with pagination.
To use the web dashboard, you need to install assets:
Managing Commands
Each command is represented as an entity with several configuration options:
- Name: The display name of the command.
- Command: The actual Symfony console command (e.g.,
app:sync-users). - Parameters: Default arguments and options (e.g.,
["--force", "prod"]). - Allow Custom Parameters: If enabled, users can provide additional parameters when running the command.
- Async: Enable asynchronous execution via Symfony Messenger.
- Save History: Whether to record execution history in the database.
- Save Output: Save the command's stdout/stderr in the history record.
- Voter Class: Specify a Symfony Voter class or a security role (e.g.,
ROLE_ADMIN) to restrict command execution based on custom logic. - Active: Easily enable/disable command from being executed.
- Description: Add notes about the command's purpose.
When adding a command, specify its name and optional default parameters.
The Parameters field must be a JSON array of strings. These are arguments and options passed to the command.
Example for app:example --fix:
- Name:
app:example - Parameters:
["--fix"]
Example for app:example arg1 --option=value:
- Name:
app:example - Parameters:
["arg1", "--option=value"]
1. List Commands
Retrieve a list of all active commands that can be executed via the web interface.
Endpoint: GET /danilovl/web-command/api/commands/
Route Name: danilovl_web_commands
Response (200 OK):
2. Run Command
Execute a command.
Endpoint: POST /danilovl/web-command/api/commands/{id}/run
Route Name: danilovl_web_command_run
Request Body:
Response (200 OK - Synchronous execution):
Response (202 Accepted - Asynchronous execution):
Returned when the command has async: true and asynchronous execution is enabled.
Response (404 Not Found):
3. List Histories
Retrieve a paginated list of histories for a specific command.
Endpoint: GET /danilovl/web-command/api/commands/{command}/histories
Route Name: danilovl_web_command_histories
Path Parameters:
command: The ID of the command.
Query Parameters:
page(optional): Page number (default: 1)
Response (200 OK):
4. Get History Details
Retrieve details and output of a specific history record.
Endpoint: GET /danilovl/web-command/api/commands/histories/{id}
Route Name: danilovl_web_command_history_detail
Response (200 OK):
Response (404 Not Found):
5. Get Job Status
Retrieve the status of a specific job.
Endpoint: GET /danilovl/web-command/api/jobs/{id}/status
Route Name: danilovl_web_command_job_status
Response (200 OK):
Security
Voter
Each command can be protected by a Symfony Voter. Specify a Voter Class (or a role like ROLE_ADMIN) in the command configuration. The bundle will check permissions using AuthorizationCheckerInterface::isGranted().
URL Security
To restrict access to the dashboards and API to specific roles, configure Symfony's access_control in config/packages/security.yaml:
Events
The bundle dispatches events during the command execution lifecycle, allowing you to intercept and modify the process.
CommandStartEvent
Dispatched before a command is executed.
Usage:
- Cancel command execution.
- Modify command input.
- Add or modify meta information.
CommandEndEvent
Dispatched after a command has finished execution (successfully or with an error).
Meta Information
The History entity includes a metaInfo field (JSON). By default, if the Symfony Security component is available, it automatically stores:
userId: ID of the current user.userIdentifier: Identifier of the current user.
You can customize this data via CommandStartEvent::setMetaInfo(). If you set it to null, no meta information will be saved.
Database Schema Example
License
The WebCommandBundle is open-sourced software licensed under the MIT license.
All versions of web-command-bundle with dependencies
doctrine/doctrine-bundle Version ^3.2.2
doctrine/orm Version ^3.6.2
easycorp/easyadmin-bundle Version ^4.27.6
symfony/asset Version ^8.0
symfony/console Version ^8.0
symfony/event-dispatcher Version ^8.0
symfony/framework-bundle Version ^8.0
symfony/messenger Version ^8.0
symfony/process Version ^8.0
symfony/twig-bundle Version ^8.0