Skip to content

Tiny PHP package to help you determine whether your PHP app is using a command line interface or a web interface

License

Notifications You must be signed in to change notification settings

natokpe/php-interface

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PhpInterface

Use this package to determine what type of interface your PHP app is using to run.

Software License release repo size file size

Installation

Composer

The recommended way of including this package in your project is via Composer

$ composer require natokpe/php-interface

Usage

To use the package, you can simply do something like this

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

You can also use either of the isCli() or isWeb() methods to check

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
}

Additionally, you may want to know if PHP is using a CGI based interface. Use the isCgi() method to check.

if ( $interface->isCgi() ) {
  echo 'cgi'; // will print 'cgi' if PHP is using a CGI based interface to run
}

You can use PhpInterface without having to instantiate the class via the getType() static method, like this

echo PhpInterface::getType(); // will print either 'cli' or 'web' depending on which type of interface PHP is using

The getType() static method is similar to which() method.

That's it! I hope you like it and find it useful.

Thank you.

About

Tiny PHP package to help you determine whether your PHP app is using a command line interface or a web interface

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages