* fixed typo
[lhc/web/wiklou.git] / includes / Init.php
1 <?php
2
3 /**
4 * Some functions that are useful during startup.
5 */
6 class MWInit {
7 static $compilerVersion;
8
9 /**
10 * Get the version of HipHop used to compile, or false if MediaWiki was not
11 * compiled. This works by having our build script insert a special function
12 * into the compiled code.
13 */
14 static function getCompilerVersion() {
15 if ( self::$compilerVersion === null ) {
16 if ( self::functionExists( 'wfHipHopCompilerVersion' ) ) {
17 self::$compilerVersion = wfHipHopCompilerVersion();
18 } else {
19 self::$compilerVersion = false;
20 }
21 }
22 return self::$compilerVersion;
23 }
24
25 /**
26 * Returns true if we are running under HipHop, whether in compiled or
27 * interpreted mode.
28 */
29 static function isHipHop() {
30 return function_exists( 'hphp_thread_set_warmup_enabled' );
31 }
32
33 /**
34 * Get a fully-qualified path for a source file relative to $IP. Including
35 * such a path under HipHop will force the file to be interpreted. This is
36 * useful for configuration files.
37 */
38 static function interpretedPath( $file ) {
39 global $IP;
40 return "$IP/$file";
41 }
42
43 /**
44 * If we are running code compiled by HipHop, this will pass through the
45 * input path, assumed to be relative to $IP. If the code is interpreted,
46 * it will converted to a fully qualified path. It is necessary to use a
47 * path which is relative to $IP in order to make HipHop use its compiled
48 * code.
49 */
50 static function compiledPath( $file ) {
51 global $IP;
52
53 if ( defined( 'MW_COMPILED' ) ) {
54 return $file;
55 } else {
56 return "$IP/$file";
57 }
58 }
59
60 /**
61 * Determine whether a class exists, using a method which works under HipHop.
62 *
63 * Note that it's not possible to implement this with any variant of
64 * class_exists(), because class_exists() returns false for classes which
65 * are compiled in.
66 *
67 * Calling class_exists() on a literal string causes the class to be made
68 * "volatile", which means (as of March 2011) that the class is broken and
69 * can't be used at all. So don't do that. See
70 * https://github.com/facebook/hiphop-php/issues/314
71 */
72 static function classExists( $class ) {
73 try {
74 $r = new ReflectionClass( $class );
75 } catch( ReflectionException $r ) {
76 $r = false;
77 }
78 return $r !== false;
79 }
80
81 /**
82 * Determine whether a function exists, using a method which works under
83 * HipHop.
84 */
85 static function functionExists( $function ) {
86 try {
87 $r = new ReflectionFunction( $function );
88 } catch( ReflectionException $r ) {
89 $r = false;
90 }
91 return $r !== false;
92 }
93 }