1. Go to this page and download the library: Download danilovl/web-command-bundle library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
use Danilovl\WebCommandBundle\Event\CommandStartEvent;
use Symfony\Component\EventDispatcher\Attribute\AsEventListener;
#[AsEventListener]
class CommandStartListener
{
public function __invoke(CommandStartEvent $event): void
{
if ($someCondition) {
$event->setShouldContinue(false);
$event->setReason('Reason for cancellation');
}
$metaInfo = $event->getMetaInfo() ?? [];
$metaInfo['custom_key'] = 'custom_value';
$event->setMetaInfo($metaInfo);
}
}
use Danilovl\WebCommandBundle\Event\CommandEndEvent;
use Symfony\Component\EventDispatcher\Attribute\AsEventListener;
#[AsEventListener]
class CommandEndListener
{
public function __invoke(CommandEndEvent $event): void
{
$exitCode = $event->getExitCode();
$output = $event->getOutput();
// Do something with the result
}
}