PHP code example of switon / cli

1. Go to this page and download the library: Download switon/cli 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/ */

    

switon / cli example snippets


use Switon\Core\Attribute\Autowired;
use Switon\Core\ConsoleInterface;

/**
 * Send a greeting.
 */
class GreetCommand
{
    #[Autowired] protected ConsoleInterface $console;

    /**
     * Say hello to one user.
     *
     * @param string $name Recipient name.
     * @param bool $shout Uppercase the message.
     */
    public function helloAction(string $name = 'world', bool $shout = false): void
    {
        $message = $shout ? 'HELLO, {name}!' : 'Hello, {name}!';
        $this->console->success($message, ['name' => $name]);
    }
}