1. Go to this page and download the library: Download survos/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/ */
survos / command-bundle example snippets
$logger->info($institution, ['tui.slot' => 'header']); // → process.slots['header'], shown live
namespace App\Command;
use App\Repository\PostRepository;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Attribute\Option;
use Symfony\Component\Console\Style\SymfonyStyle;
final class PostCommands
{
public function __construct(private PostRepository $posts) {}
#[AsCommand('app:list-posts', 'List the posts')]
public function list(
SymfonyStyle $io,
#[Option(description: 'Limit the number of posts')]
int $limit = 50,
): void {
$rows = array_map(
fn ($p) => [$p->getId(), $p->getTitle(), $p->getAuthor()->getFullName()],
$this->posts->findBy([], [], $limit),
);
$io->table(['id', 'title', 'author'], $rows);
}
}
#[\Castor\Attribute\AsSymfonyTask()]
bash
symfony new castor-command-demo --webapp && cd castor-command-demo
sed -i "s|# MAILER_DSN|MAILER_DSN|" .env
bin/console make:command app:castor-test
cat > castor.php <<'END'
use Castor\Attribute\AsTask;
use function Castor\io;
use function Castor\capture;
use function Castor\import;
import(__DIR__ . '/src/Command/CastorTestCommand.php');
#[AsTask(description: 'Welcome to Castor!')]
function hello(): void
{
$currentUser = capture('whoami');
io()->title(sprintf('Hello %s!', $currentUser));
}
END
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.