PHP Classes

File: Example1.php

Recommend this page to a friend!
  Classes of Mat Jung   PHP Command Line Parser   Example1.php   Download  
File: Example1.php
Role: Example script
Content type: text/plain
Description: Example script
Class: PHP Command Line Parser
Invoke functions to process command-line arguments
Author: By
Last change:
Date: 1 year ago
Size: 885 bytes
 

Contents

Class file image Download
<?php
/* License: OSL-3.0
   To be launched in shell environment
   php Example1.php
*/

require 'vendor/autoload.php';
use
Siims\clp\clp;

$options = [
   
"actions" => [
       
"h|help" => "displayHelp",
       
"hello" => "callHello"
   
],
   
"flags" => [
       
"try-run","verbose","debug"
   
],
   
"values" => [
       
"hello" => "world"
   
],
   
"events" => [
       
"onAfterProcess" => "parsingCommandLineFinished",
       
"onNoOptions" => "displayHelp"
   
]
    ];

$hello = new clp($argv,$options);

function
displayHelp() {
    global
$argv;
    echo
"$argv[0] hello=\"your_name\" | --h | -help | verbose | debug\n";
}

function
parsingCommandLineFinished($config) {
    echo
"Finished parsing command line.\n";
   
print_r($config);
}

function
callHello($config,$method) {
    echo
"Hello {$config["values"]["hello"]}\n";
    echo
"Implemented by $method\n";
}