PHP code example of krisanalfa / konsole

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

    

krisanalfa / konsole example snippets


namespace Konsole\Commands;

use Konsole\Command;

class SendEmails extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = '';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '';

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
    }
}

/**
 * The name and signature of the console command.
 *
 * @var string
 */
protected $signature = 'email:send {user}';

// Optional argument...
protected $signature = 'email:send {user?}'

// Optional argument with default value...
protected $signature = 'email:send {user=foo}'

/**
 * The name and signature of the console command.
 *
 * @var string
 */
protected $signature = 'email:send {user} {--pretending}';

/**
 * The name and signature of the console command.
 *
 * @var string
 */
protected $signature = 'email:send {user} {--pretending=}';

protected $signature = 'email:send {user} {--pretending=default}';

protected $signature = 'email:send {user} {--P|pretending}';

protected $signature = 'email:send {user*}';

protected $signature = 'email:send {user} {--id=*}';

/**
 * The name and signature of the console command.
 *
 * @var string
 */
protected $signature = 'email:send
                        {user : The ID of the user}
                        {--pretending= : Whether the job should be prentended}';

/**
 * Execute the console command.
 *
 * @return mixed
 */
public function handle()
{
    $userId = $this->argument('user');

    //
}

$arguments = $this->argument();

// Retrieve a specific option...
$isPretending = ($this->option('pretending') !== null);

// Retrieve all options...
$options = $this->option();

/**
 * Execute the console command.
 *
 * @return mixed
 */
public function handle()
{
    $name = $this->ask('What is your name?');
}

$password = $this->secret('What is the password?');

// The default answer is 'no|N'
if ($this->confirm('Do you wish to continue? [y|N]')) {
    // Do something if user answer 'yes|y'
}

$name = $this->anticipate('What is your name?', ['Alfa', 'Fitria']);

$name = $this->choice('What is your name?', ['Alfa', 'Fitria'], $default);

/**
 * Execute the console command.
 *
 * @return mixed
 */
public function handle()
{
    $this->info('Display this on the screen');
}

$this->warn('Something went wrong!');

$this->error('Something went wrong!');

$this->line('Display this on the screen');

$this->suggest('Better you pick Sven, because you have Magnus on your side.');

$headers = ['Name', 'Email'];

$this->table($headers, $collection->toArray());

$bar = $this->output->createProgressBar(count($users));

foreach ($users as $user) {
    $this->performTask($user);

    $bar->advance();
}

$bar->finish();

'commands' => [
    'Konsole\Commands\SendEmails',
    'Konsole\Commands\GenerateCommand',
],

$konsole->registerCommand('Konsole\Commands\SendEmails');

$konsole->registerCommand([
    'Konsole\Commands\FooBarBaz',
    'Konsole\Commands\SendEmails',
    'Konsole\Commands\AnotherCommand',
]);

/**
 * Execute the console command.
 *
 * @return mixed
 */
public function handle()
{
    $this->call('email:send', [
        'user' => 1, '--pretending' => 'default'
    ]);

    //
}

$this->callSilent('email:send', [
    'user' => 1, '--pretending' => 'default'
]);

$konsole->log->emergency($message);
$konsole->log->alert($message);
$konsole->log->critical($message);
$konsole->log->message($message);
$konsole->log->warning($message);
$konsole->log->notice($message);
$konsole->log->info($message);
$konsole->log->debug($message);

$konsole->make('log')->info('User failed to login.', ['id' => $user->id]);

$monolog = $konsole->make('log');
sh
php konsole list
sh
php konsole help generate
sh
php konsole generate SendEmails
sh
php konsole email:send 1 --pretending
sh
php konsole email:send 1 --pretending=default