My Journey Creating a Chameleon CLI Tool Inspired by Laravel Installer and Symfony Create-Project

Github Link: https://github.com/kzorluoglu/chameleon-installer

Asciiname URL: https://asciinema.org/a/rJL6Se0R943agLPneUSNmO3h4

asciinema Animation:

Usage

You can install the Chameleon Shop Installer globally using Composer:

composer global require kzorluoglu/chameleon-installer

Creating a New Project

Once installed, you can create a new Chameleon project using:

chameleon create /path/to/your/new/shop

Replace /path/to/your/new/shop with the desired directory for your new Chameleon Shop.

The Inspiration:

My journey began with Laravel’s CLI. Working with Laravel’s streamlined command-line interface always seemed to boost my productivity. On the flip side, my day job involves Symfony, which offers the powerful Symfony CLI. This overlap of technologies sparked an idea – why not create a globally runnable PHP installer binary using Composer? This project wasn’t just about building a tool; it was about deepening my understanding of PHP’s capabilities.

The starting point was an existing web-based installer I had developed earlier. This web installer, with its efficient workflow, became my blueprint. I decided to use Symfony Console and YAML features, aiming to leverage Symfony’s robustness and flexibility.

Transitioning from a web installer to a CLI tool was challenging yet exhilarating. I dove into the Symfony Console documentation, finding SymfonyStyle particularly useful for beautifying the console output. Every line of code was a learning opportunity, helping me understand the intricacies of CLI development in PHP.

One fascinating aspect of the Laravel Installer is its entry point, the bin/laravel file. This script begins with #!/usr/bin/env php, a shebang line that makes the file executable directly from the command line. It then conditionally loads Composer’s autoloader, crucial for accessing the Laravel framework and its dependencies.

Here’s a simplified snippet of Laravel’s approach:

#!/usr/bin/env php
<?php

// Autoload files based on the project's context
if (file_exists(__DIR__ . '/../../../autoload.php')) {
    require __DIR__ . '/../../../autoload.php';
} else {
    require __DIR__ . '/../vendor/autoload.php';
}

// ... Laravel Installer logic ...

This project was more than just a tool; it was a bridge between Laravel’s elegance and Symfony’s power. It not only enhanced my technical skills but also deepened my appreciation for PHP’s versatility.

Expanding on the Laravel inspiration, I integrated Symfony’s styling capabilities to enhance the user interface of my tool. Symfony Console’s SymfonyStyle class offers an elegant way to format console output, making interactions more user-friendly.

Here’s an example of how I used SymfonyStyle in the execute method:

protected function execute(InputInterface $input, OutputInterface $output): int {
    $io = new SymfonyStyle($input, $output);
    $io->title('Chameleon Creating Tool');

    $io->section('Requirement Checks started');
    // Requirement check logic...

    $io->error("Error executing query: ".$e->getMessage());
}

Views: 238