1. Go to this page and download the library: Download simsoft/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/ */
use Symfony\Component\Console\Input\InputArgument;
Application::command('example:closure:command2', function() {
$name = $this->argument('name');
$this->info("I got your name: $name");
})
->purpose('Get user name')
->input(function(){
$this->addArgument('name', InputArgument::REQUIRED, 'Name
/**
* @throws \Throwable
*/
protected function handle(): void
{
$this->info('Hello World'); // Write info message
$this->comment('Comment text');
$this->question('My Question?');
$this->error('Warning'); // Write error message
$this->line('Simple line'); // Write simple un-formatted message
$this->errorBlock('Block Header', 'Block message');
$this->newLine(); // Write a single blank line
$this->newLine(3); // Write three blank lines
}
/**
* @throws \Throwable
*/
protected function handle(): void
{
// Simple question
// Other argument: $default.
$name = $this->ask('What is your name?');
$this->info("Your name is $name");
// Hide user input question
// Other argument: $default
$secret = $this->secret('Please tell me a secret?');
$this->info("Your secret is $secret");
// Asking for confirmation.
// Other argument: $default.
if ($this->confirm('Are you above 18yo (y/n)?')) {
$this->info('You have grow up!');
} else {
$this->info("You are very young!");
}
// Multiple choice questions.
// Other arguments: $defaultIndex, $maxAttempts, $allowMultipleSelections.
$myChoice = $this->choice('Which color do you like?', ['Yellow', 'Orange', 'Blue']);
$this->info("You have selected $myChoice");
}