162 words
1 minutes
Introduction to Castor: A Task Runner in PHP

Introduction to Castor: A Task Runner in PHP#

I always carry a Makefile in my projects—a Makefile that helps me execute various Docker commands. This saves me from repeatedly typing docker compose exec .... Since I’m not a shell expert, adding even a simple command can quickly become complex.

During Symfony Live 2024, @Lyrixx (from Jolicode) gave a lightning talk on Castor. I had already started exploring it a while back without diving in seriously, but @Lyrixx inspired me to take another look. I must admit, I’ve just adopted a beaver!

What is Castor?#

The concept is similar to a Makefile—a “Task Runner.” The big advantage is that it’s written in PHP, making it feel like home! Here’s the classic “Hello World” example:

#[AsTask(description: 'Welcome to Castor!')]
function hello(): void
{
    $currentUser = capture('whoami');

    io()->title(sprintf('Hello %s!', $currentUser));

    notify('Welcome to Castor!');
}

And voilà—a command! I encourage you to check out the official documentation, which is very well done. Castor uses a castor.php file where you’ll define your commands.