Skip to content

arcanisgk/WEB-CLI-Detector

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

WEB-CLI-Detector

Detection of execution by command (Terminal) or web environment.

Acronym: [WEB-CLI-Detector].

Name: WEB-CLI-Detector.

Dependencies: Stand Alone / PHP v7.4.

What does [WEB-CLI-Detector] do?

is a very simple PHP [WEB-CLI-Detector] implementation that allows you to easily validate if the PHP execution is taking place from a web environment or from the execution of commands (terminal)

Why use [WEB-CLI-Detector]?

Developers need the ability to validate in which environment their libraries or applications are running, this helps decision making depending on the needs or requirements, making it easier for all developers on the same team to use the same validation.

Help to improve [WEB-CLI-Detector]?

if you want to collaborate with the development of the library; You can express your ideas or report any situation related to this in: https://github.com/arcanisgk/WEB-CLI-Detector/issues

[WEB-CLI-Detector] Configuration:

None necessary.

[WEB-CLI-Detector] Installation:

composer require arcanisgk/web-cli-detector

[WEB-CLI-Detector] Usage:

Instance of Class:

use IcarosNet\WebCLIToolKit\WebCLIDetector;
require __DIR__.'\..\vendor\autoload.php';
$wc_detector = new WebCLIDetector();

Implementation of Class:

if ($wc_detector->isCLI()) {
    echo 'Running from CLI'.PHP_EOL;
}

if ($wc_detector->isWEB()) {
    echo 'Running from WEB<br>';
}

echo 'Get Raw Environment: '.$wc_detector->getEnvironment();

Other Way to implement:

this is an option to instance and validate in one line

if (WebCLIDetector::getInstance()->isCLI()) {

    //your logic

}

Example Output:

CLI Test

Image of Example Output1

Web Test

Image of Example Output2

Contributors