Download the PHP package amsify42/php-command-line without Composer
On this page you can find all versions of the php package amsify42/php-command-line. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download amsify42/php-command-line
More information about amsify42/php-command-line
Files in amsify42/php-command-line
Package php-command-line
Short Description This is a php package for dealing with command line parameters
License MIT
Homepage https://github.com/amsify42/php-command-line
Informations about the package php-command-line
PHP Command Line
This is a php package for dealing with command line parameters.
Installation
Table of Contents
- Introduction
- Getting Parameters
- Double Hyphen Param
- To String
- CLI Task
1. Introduction
The class Amsify42\CommandLine\CommandLine
class helps get the cli parameter passed in any of the format.
or
or
2. Getting Parameters
To get all the parameters passed you can call this method
or with helper method
To get the specific key param
or
To check the whether the cli param exist
or
It will return true
if exist else false
3. Double Hyphen Param
The helper class can also detect the param name passed with double hyphen
We can use the same isParam
method to check whether global param passed or not.
4. To String
We can also convert all the cli params passed back to the string with this method.
or
5. CLI Task
Create a class under any directory, Example: /app/Task/
You can run this script from console from other file like test.php
and run this file
If script file name is passed directly from command line
and run the file with task file name
For programmatically running the script, you can use this method
For running script in background asynchronously, you need to pass 3th param as true
Params/Validations
You can also pass cli params along with script like this
Through method
and can collect these params in the script
To validate and check whether the params exist, you can do this
Further script will not be executed if validation fails.