GithubHelp home page GithubHelp logo

cliphp's Introduction

This is a simple to use Command Line Interface ( CLI ) PHP class that allows for user input.

This script can take parameters to your script in 3 different ways...

1.)  User Input

   - With this method, you can allow your script to ask the user for the parameters for your script.

<?php
  require_once('cli.php');

  // Create a new CLI object.
  $cli = new CLIPHP();

  // Ask the user for their first name.
  $cli->get('first', "What is your first name?");

  // Ask the user for their last name.
  $cli->get('last', "What is your last name?");

  // Now print the results.
  print $cli->args['first'];
  print $cli->args['last'];
?>

2.)  Cached User Input

   - With this method, you can cache the user results inside of a "config" file on the root path of where this script is ran.
   - Using this method, they will be asked for the parameters only once, and then every other time the script is ran, the 
     cached results will populate the parameters.  Like so...

<?php
  require_once('cli.php');

  // Create a new CLI object.
  $cli = new CLIPHP();

  // Ask the user for their first name.  PASS TRUE TO CACHE THE RESULT!!!
  $cli->get('first', "What is your first name?", TRUE);

  // Ask the user for their last name.  PASS TRUE TO CACHE THE RESULT!!!!
  $cli->get('last', "What is your last name?", TRUE);

  // Now print the results.
  print $cli->args['first'];
  print $cli->args['last'];

  // Now create a separate CLI object.
  $cli2 = new CLIPHP();
  
  // Print's the cached results from the first object.
  print $cli2->args['first'];
  print $cli2->args['last'];
?>

3.)  Direct arguments...

   - With this, you can just pass the arguments directly using the "-param value" method.

php mycli.php -name "Travis" -last "Tidwell"

   - Then inside of your script, you just need to provide the following..
   - It will first check to see if values have been passed as arguments, and then if so, it will use those instead.


<?php
  require_once('cli.php');

  // Create a new CLI object.
  $cli = new CLIPHP();

  // Ask the user for their first name.
  $cli->get('first', "What is your first name?");

  // Ask the user for their last name.
  $cli->get('last', "What is your last name?");

  // Now print the results.
  print $cli->args['first'];
  print $cli->args['last'];
?>

cliphp's People

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.