MediaWiki  REL1_19
MWFunction.php
Go to the documentation of this file.
00001 <?php
00002 
00021 class MWFunction {
00022 
00028         protected static function cleanCallback( $callback ) {
00029                 if( is_string( $callback ) ) {
00030                         if ( strpos( $callback, '::' ) !== false ) {
00031                                 // PHP 5.1 cannot use call_user_func( 'Class::Method' )
00032                                 // It can only handle only call_user_func( array( 'Class', 'Method' ) )
00033                                 $callback = explode( '::', $callback, 2);
00034                         }
00035                 }
00036 
00037                 if( count( $callback ) == 2 && $callback[0] == 'self' || $callback[0] == 'parent' ) {
00038                         throw new MWException( 'MWFunction cannot call self::method() or parent::method()' );
00039                 }
00040 
00041                 // Run autoloader (workaround for call_user_func_array bug: http://bugs.php.net/bug.php?id=51329)
00042                 is_callable( $callback );
00043 
00044                 return $callback;
00045         }
00046 
00051         public static function call( $callback ) {
00052                 $callback = self::cleanCallback( $callback );
00053 
00054                 $args = func_get_args();
00055 
00056                 return call_user_func_array( 'call_user_func', $args );
00057         }
00058 
00064         public static function callArray( $callback, $argsarams ) {
00065                 $callback = self::cleanCallback( $callback );
00066                 return call_user_func_array( $callback, $argsarams );
00067         }
00068 
00074         public static function newObj( $class, $args = array() ) {
00075                 if( !count( $args ) ) {
00076                         return new $class;
00077                 }
00078 
00079                 $ref = new ReflectionClass( $class );
00080                 return $ref->newInstanceArgs( $args );
00081         }
00082 
00083 }