PHP Classes

File: Example/run.php

Recommend this page to a friend!
  Classes of nvb   PHP Command Line Arguments Parser Class   Example/run.php   Download  
File: Example/run.php
Role: Example script
Content type: text/plain
Description: Example script
Class: PHP Command Line Arguments Parser Class
Parse CLI script arguments to extract its values
Author: By
Last change:
Date: 3 years ago
Size: 1,338 bytes
 

Contents

Class file image Download
<?php
/**
 * @author: stev leibelt <artodeto@bazzline.net>
 * @since: 2015-04-16
 */

require_once __DIR__ . '/../vendor/autoload.php';

$arguments = new \Net\Bazzline\Component\Cli\Arguments\Arguments($argv);

if (
$arguments->hasArguments()) {
    echo
$arguments->getNumberOfArguments() . ' arguments provided:' . PHP_EOL;
    foreach (
$arguments->getArguments() as $argument) {
        echo
' ' . $argument . PHP_EOL;
    }
} else {
    echo
'no values provided' . PHP_EOL;
}

if (
$arguments->hasLists()) {
    echo
$arguments->getNumberOfLists() . ' lists provided:' . PHP_EOL;
    foreach (
$arguments->getLists() as $name => $values) {
        echo
' ' . $name . PHP_EOL;
        foreach (
$values as $value) {
            echo
' ' . $value . PHP_EOL;
        }
    }
} else {
    echo
'no values provided' . PHP_EOL;
}

if (
$arguments->hasFlags()) {
    echo
$arguments->getNumberOfFlags() . ' flags provided:' . PHP_EOL;
    foreach (
$arguments->getFlags() as $flag) {
        echo
' ' . $flag . PHP_EOL;
    }
} else {
    echo
'no flags provided' . PHP_EOL;
}

if (
$arguments->hasValues()) {
    echo
$arguments->getNumberOfValues() . ' values provided:' . PHP_EOL;
    foreach (
$arguments->getValues() as $value) {
        echo
' ' . $value . PHP_EOL;
    }
} else {
    echo
'no values provided' . PHP_EOL;
}