PHP code example of italix / console

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

    

italix / console example snippets


namespace App\Console;

use Italix\Console\{BaseCommand, Input, Output};
use Italix\Orm\DataManager;

final class PurgeTokensCommand extends BaseCommand
{
    /** Injected by the runner — protected, because BaseCommand assigns it */
    protected DataManager $dm;

    public static function name_code(): string  { return 'tokens:purge'; }
    public static function summary(): string { return 'Delete expired verification tokens.'; }

    public static function depends_on(): array
    {
        return ['dm' => DataManager::class];
    }

    public function run(Input $in, Output $out): int
    {
        $days_n = $in->int_option('older-than', 30);

        if ($in->flag('dry-run')) {
            $out->comment("Would purge tokens older than {$days_n} days.");

            return 0;
        }

        $done_n = $this->dm->execute('DELETE FROM …')->rowCount();
        $out->success("{$done_n} tokens purged.");

        return 0;
    }
}

'console.commands' => [
    \App\Console\MigrateCommand::class,
    \App\Console\PurgeTokensCommand::class,
],

$out->line('plain');           // stdout
$out->info('cyan');            // stdout
$out->success('green');        // stdout
$out->comment('dim');          // stdout
$out->warn('yellow');          // stderr
$out->error('red');            // stderr
$out->table(['a', 'b'], $rows);

$config = base_dir'] = $base_dir;
$config['host']     = $host;

$engine = new Engine($config);

exit(console($config['console.commands'] ?? [], $engine->registry(), 'ix', 'Acme')->run($argv));
bash
php bin/ix                       # every command, grouped
php bin/ix migrate --dry-run     # what would run, without running it
php bin/ix encode:lint           # template output that is not encoded
php bin/ix version               # every Italix library and its version