natokpe / php-interface
小巧的PHP包,帮助您确定您的PHP应用是使用命令行接口还是Web接口
1.0.0
2021-07-27 23:34 UTC
Requires
- php: >=7.4
README
使用此包来确定您的PHP应用使用哪种类型的接口来运行。
安装
Composer
将此包包含到您的项目中,推荐使用Composer
$ composer require natokpe/php-interface
用法
要使用此包,您可以这样做
use Natokpe\PhpInterface\PhpInterface; require_once __DIR__ . '/vendor/autoload.php'; $interface = new PhpInterface; echo $interface->which(); // will print 'cli' if PHP is using CLI to run or 'web' if PHP is run from web
您也可以使用 isCli() 或 isWeb() 方法来检查
if ( $interface->isCli() ) { echo 'cli'; // will print 'cli' if PHP is using CLI to run } if ( $interface->isWeb() ) { echo 'web'; // will print 'web' if PHP is run from web }
此外,您可能还想知道PHP是否使用基于CGI的接口。使用 isCgi() 方法来检查。
if ( $interface->isCgi() ) { echo 'cgi'; // will print 'cgi' if PHP is using a CGI based interface to run }
您可以使用 PhpInterface,无需通过 getType() 静态方法实例化类,如下所示
echo PhpInterface::getType(); // will print either 'cli' or 'web' depending on which type of interface PHP is using
getType() 静态方法类似于 which() 方法。
就是这样!希望您喜欢它并觉得它有用。
谢谢。