PHP code example of amsify42 / php-command-line

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

    

amsify42 / php-command-line example snippets


use \Amsify42\CommandLine\CommandLine;
CommandLine::getParams();

cli_get_params();

CommandLine::getParam('id');

cli_get_param('id');

CommandLine::isParam('id');

cli_is_param('id');

echo CommandLine::toString();

echo cli_to_string();



namespace App\Task;

use Amsify42\CommandLine\Task\BaseTask;

class Test extends BaseTask
{
    public function init()
    {
     	printMsg("Doing something");   
    }
}


fy42\CommandLine\Task::run(\App\Task\Test::class);


$task = new \Amsify42\CommandLine\Task();
$task->process();

\Amsify42\CommandLine\Task::run(\App\Task\Test::class);

\App\Console::run(\App\Task\Test::class, [], true);

\Amsify42\CommandLine\Task::run(\App\Task\Test::class, ['id' => 1, 'name' => 'Kyro']);



namespace App\Task;

use Amsify42\CommandLine\Task\BaseTask;

class Test extends BaseTask
{
    public function init()
    {
    	$id 	= $this->input('id');
    	$name 	= $this->input('name');
     	// do the remaining
    }
}

public function init()
{
	$this->validate(['id', 'name']);
 	// do the remaining
}

$ composer 

php file.php 42 amsify "some description"

php file.php -id 42 -name amsify -desc "some description"

php file.php -id=42 -name=amsify -desc="some description"

php file.php --global

php test.php

php test.php App\Task\Test

php test.php App\Task\Test -id 1 -name Kyro