PHP Classes

File: README.md

Recommend this page to a friend!
  Classes of Francisco Nez   PHP Web or Cli Detect   README.md   Download  
File: README.md
Role: Documentation
Content type: text/markdown
Description: Documentation
Class: PHP Web or Cli Detect
Detect if PHP is running from CLI or a Web server
Author: By
Last change:
Date: 0 years ago
Size: 2,138 bytes
 

Contents

Class file image Download

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
or 
composer require arcanisgk/web-cli-detector --dev

[WEB-CLI-Detector] Usage:

Instance of Class:


use IcarosNet\WebCLIDetector\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

  • (c) 2020 - 2022 Walter Francisco Nez Cruz icarosnet@gmail.com Donate