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