PHPackages                             amsify42/php-command-line - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [CLI &amp; Console](/categories/cli)
4. /
5. amsify42/php-command-line

ActiveLibrary[CLI &amp; Console](/categories/cli)

amsify42/php-command-line
=========================

This is a php package for dealing with command line parameters

1.1(1y ago)04MITPHPPHP &gt;=7.0.0CI failing

Since Apr 30Pushed 1y ago1 watchersCompare

[ Source](https://github.com/amsify42/php-command-line)[ Packagist](https://packagist.org/packages/amsify42/php-command-line)[ Docs](https://github.com/amsify42/php-command-line)[ RSS](/packages/amsify42-php-command-line/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (3)Versions (3)Used By (0)

PHP Command Line
================

[](#php-command-line)

This is a php package for dealing with command line parameters.

### Installation

[](#installation)

```
$ composer require amsify42/php-command-line

```

Table of Contents
-----------------

[](#table-of-contents)

1. [Introduction](#1-introduction)
2. [Getting Parameters](#2-getting-parameters)
3. [Double Hyphen Param](#3-double-hyphen-param)
4. [To String](#4-to-string)
5. [CLI Task](#5-cli-task)

### 1. Introduction

[](#1-introduction)

The class `Amsify42\CommandLine\CommandLine` class helps get the cli parameter passed in any of the format.

```
php file.php 42 amsify "some description"

```

or

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

```

or

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

```

### 2. Getting Parameters

[](#2-getting-parameters)

To get all the parameters passed you can call this method

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

or with helper method

```
cli_get_params();
```

To get the specific key param

```
CommandLine::getParam('id');
```

or

```
cli_get_param('id');
```

To check the whether the cli param exist

```
CommandLine::isParam('id');
```

or

```
cli_is_param('id');
```

It will return `true` if exist else `false`

### 3. Double Hyphen Param

[](#3-double-hyphen-param)

The helper class can also detect the param name passed with double hyphen

```
php file.php --global

```

We can use the same `isParam` method to check whether **global** param passed or not.

### 4. To String

[](#4-to-string)

We can also convert all the cli params passed back to the string with this method.

```
echo CommandLine::toString();
```

or

```
echo cli_to_string();
```

### 5. CLI Task

[](#5-cli-task)

Create a class under any directory, Example: `/app/Task/`

```
