env.php ➔ NixOs()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 0
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Functions about runtime environment and server env variant
4
 *
5
 * Original is_cli.php and nixos.php merged in this.
6
 * @package		fwolflib
7
 * @copyright	Copyright 2006-2010, Fwolf
8
 * @author		Fwolf <[email protected]>
9
 * @since		2006-07-08
10
 */
11
12
13
require_once(dirname(__FILE__) . '/../fwolflib.php');
14
15
16
/**
17
 * Force page visit through https only
18
 *
19
 * @deprecated      Use Fwlib\Util\Env::forceHttps()
20
 */
21
function ForceHttps() {
22
	if (!isset($_SERVER['HTTPS']) || 'on' != $_SERVER['HTTPS']) {
23
		$s = 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
24
		header("Location: $s");
25
	}
26
} // end of function ForceHttps
27
28
29
/**
30
 * Check if this program is running under cli mod, or is viewing in browser.
31
 *
32
 * Tested in nix os only
33
 *
34
 * @deprecated      Use Fwlib\Util\Env::isCli()
35
 * @return	boolean
36
 */
37
function IsCli() {
38
/*
39
	if (isset($_ENV['_']) && (('/usr/bin/php' == substr($_ENV['_'], 0, 12))
40
		|| ($_SERVER["SCRIPT_FILENAME"] == $_ENV['_'])))    //chmod +x xxx.php and run itself
41
*/
42
	if (!empty($_ENV['_']) || !empty($_SERVER['_']))
43
		$is_cli = true;
44
	else
45
		$is_cli = false;
46
	return($is_cli);
47
} // end of func IsCli
48
49
50
/**
51
 * 判断当前主机是否nix操作系统
52
 *
53
 * @deprecated      Use Fwlib\Util\Env::isNixOs()
54
 * @return boolean
55
 */
56
function NixOs()
57
{
58
	//采用判断执行文件全路径的第一个字符的方式
59
	if ('/' == $_SERVER['SCRIPT_FILENAME']{0})
60
		return true;
61
	else
62
		return false;
63
}
64
65
66
/**
67
 * Generate path from script to project root - P2R
68
 *
69
 * Can use in both cli mod and www mod.
70
 *
71
 * <code>
72
 * define('P2R', P2r('relate_path_to_proj_root'))
73
 * </code>
74
 * @param	string	$path	Relate path from root to here, start with no '/',
75
 * 							Better end with '/'.
76
 * @return	string
77
 */
78
function P2r($path)
79
{
80
	$s = '';
0 ignored issues
show
Unused Code introduced by
$s is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
81
	if (true == IsCli())
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
Deprecated Code introduced by
The function IsCli() has been deprecated with message: Use Fwlib\Util\Env::isCli()

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
82
		$s = dirname($_SERVER['SCRIPT_NAME']) . '/./' . $path;
83
	else
84
		$s = './' . $path;
85
86
	return $s;
87
} // end of func P2r
88
?>
0 ignored issues
show
Best Practice introduced by
It is not recommended to use PHP's closing tag ?> in files other than templates.

Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.

A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.

Loading history...
89