1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* This file is part of the Cecil/Cecil package. |
4
|
|
|
* |
5
|
|
|
* Copyright (c) Arnaud Ligny <[email protected]> |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace Cecil\Util; |
12
|
|
|
|
13
|
|
|
class Plateform |
|
|
|
|
14
|
|
|
{ |
15
|
|
|
const OS_UNKNOWN = 1; |
16
|
|
|
const OS_WIN = 2; |
17
|
|
|
const OS_LINUX = 3; |
18
|
|
|
const OS_OSX = 4; |
19
|
|
|
|
20
|
|
|
protected static $pharPath; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Running from Phar or not? |
24
|
|
|
* |
25
|
|
|
* @return bool |
26
|
|
|
*/ |
27
|
|
|
public static function isPhar() |
28
|
|
|
{ |
29
|
|
|
if (!empty(\Phar::running())) { |
30
|
|
|
self::$pharPath = \Phar::running(); |
31
|
|
|
|
32
|
|
|
return true; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
return false; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Returns the full path on disk to the currently executing Phar archive. |
40
|
|
|
*/ |
41
|
|
|
public static function getPharPath() |
42
|
|
|
{ |
43
|
|
|
if (!isset(self::$pharPath)) { |
44
|
|
|
self::isPhar(); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
return self::$pharPath; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @return bool Whether the host machine is running a Windows OS |
52
|
|
|
*/ |
53
|
|
|
public static function isWindows() |
54
|
|
|
{ |
55
|
|
|
return defined('PHP_WINDOWS_VERSION_BUILD'); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Opens a URL in the system default browser. |
60
|
|
|
* |
61
|
|
|
* @param string $url |
62
|
|
|
*/ |
63
|
|
|
public static function openBrowser($url) |
64
|
|
|
{ |
65
|
|
|
if (self::isWindows()) { |
66
|
|
|
passthru('start "web" explorer "'.$url.'"'); |
67
|
|
|
} else { |
68
|
|
|
passthru('which xdg-open', $linux); |
69
|
|
|
passthru('which open', $osx); |
70
|
|
|
if (0 === $linux) { |
71
|
|
|
passthru('xdg-open '.$url); |
72
|
|
|
} elseif (0 === $osx) { |
73
|
|
|
passthru('open '.$url); |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @return int |
80
|
|
|
*/ |
81
|
|
|
static public function getOS() { |
82
|
|
|
switch (true) { |
|
|
|
|
83
|
|
|
case stristr(PHP_OS, 'DAR'): return self::OS_OSX; |
84
|
|
|
case stristr(PHP_OS, 'WIN'): return self::OS_WIN; |
85
|
|
|
case stristr(PHP_OS, 'LINUX'): return self::OS_LINUX; |
86
|
|
|
default : return self::OS_UNKNOWN; |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|
This check examines a number of code elements and verifies that they conform to the given naming conventions.
You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.