PHP code example of utopia-php / cli

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

    

utopia-php / cli example snippets



Utopia\Console;
use Utopia\CLI\CLI;
use Utopia\CLI\Adapters\Generic;
use Utopia\Validator\Wildcard;

$cli = new CLI(new Generic());

$cli
    ->task('command-name')
    ->param('email', null, new Wildcard())
    ->action(function ($email) {
        Console::success($email);
    });

$cli->run();




use Utopia\CLI\CLI;
use Utopia\Console;
use Utopia\Validator\Wildcard;

CLI::setResource('res1', function() {
    return 'resource 1';
})

CLI::init()
    inject('res1')
    ->action(function($res1) {
        Console::info($res1);
    });

CLI::error()
    ->inject('error')
    ->action(function($error) {
        Console::error('Error occurred ' . $error);
    });

$cli = new CLI();

$cli
    ->task('command-name')
    ->param('email', null, new Wildcard())
    ->action(function ($email) {
        Console::success($email);
    });

$cli->run();
bash
composer 
bash
php script.php command-name [email protected]