Re: Auto Detection of Environment
| From: | Scott Mattocks | Date: | Thu, 09 Dec 2004 12:59:14 +0000 |
| Subject: | Re: Auto Detection of Environment | ||
| References: | 1 | Groups: | php.gtk.general |
| Request: | Send a blank email to php-gtk-general+get-5327@lists.php.net to get a copy of this message | ||
Doug Burkhalter wrote:
I'm looking into creating apps with PHP that could be run in three different ways: online, via command line, and through PHP-GTK. I was wondering if there was any "automatic" way to detect what environment it was being run in (online, cli, or GTK). I have a secondary plan already, containing 4 files: myapp-gtk.php (or myapp.php-gtk) - PHP-GTK version myapp-cli.php - CLI version myapp-online.php - Online version myapp.php - central fileI don't know of anyway to reliably check how the script is being run but you could have the user pass some command line arguments to decide how they want to run the script. (Warning shameless plug) You could use something like PEAR::Console_Getargs to let the user pass which version to run. From the command line they would just type: $ php myapp.php <-h|gtk|cli> to get the help screen, gtk version or cli version. In your script (after a little set up) you would just do something like this: $args = Console_Getargs::factory($config); if ($args->getValue('method') == 'gtk') {
require_once 'myapp-gtk.php';} elseif ($args->getValue('method') == 'cli') {
require_once 'myapp-cli.php';} else {
require_once 'myapp-online.php';} ... -- Scott Mattocks scott@crisscott.com http://www.crisscott.com http://pear.php.net/user/scottmattocks