Detection of execution by command (Terminal) or web environment.
Acronym: [WEB-CLI-Detector].
Name: WEB-CLI-Detector.
Dependencies: Stand Alone / PHP v7.4.
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)
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.
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
None necessary.
composer require arcanisgk/web-cli-detector
use IcarosNet\WebCLIToolKit\WebCLIDetector;
require __DIR__.'\..\vendor\autoload.php';
$wc_detector = new WebCLIDetector();
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();
this is an option to instance and validate in one line
if (WebCLIDetector::getInstance()->isCLI()) {
//your logic
}
CLI Test
Web Test
- (c) 2020 - 2022 Walter Francisco Núñez Cruz icarosnet@gmail.com