jenkins-bot has submitted this change and it was merged. Change subject: add T_PRINT operator and PHP constants ......................................................................
add T_PRINT operator and PHP constants * fix for use Foxway\Runtime::$time instead of $GLOBALS['wgFoxwayTime'] * fix for use self::getNextToken * fix for pcre functions, add namespace Foxway before ExceptionFoxway Time: 385 ms, Memory: 24.75Mb OK (402 tests, 408 assertions) Change-Id: I3cef8f07f5fe3f541dc819f9e449597483f50c23 --- M Foxway.body.php M Settings.php M includes/Compiler.php M includes/Runtime.php A includes/constants.php M includes/functions/pcre.php M tests/phpunit/includes/RuntimeTest.php 7 files changed, 326 insertions(+), 219 deletions(-) Approvals: Pastakhov: Looks good to me, approved jenkins-bot: Verified diff --git a/Foxway.body.php b/Foxway.body.php index 5deaac3..c076b61 100644 --- a/Foxway.body.php +++ b/Foxway.body.php @@ -54,7 +54,7 @@ $return = $exc->getTraceAsString(); } - $GLOBALS['wgFoxwayTime'] += microtime(true) - self::$startTime; + \Foxway\Runtime::$time += microtime(true) - self::$startTime; return \UtfNormal::cleanUp($return); } @@ -84,7 +84,7 @@ self::getScope($frame) ); } catch (Exception $exc) { - $GLOBALS['wgFoxwayTime'] += microtime(true) - self::$startTime; + \Foxway\Runtime::$time += microtime(true) - self::$startTime; return $exc->getTraceAsString(); } @@ -101,7 +101,7 @@ $return .= self::insertGeneral( $parser, $parser->recursiveTagParse(implode($result),$frame) ); } - $GLOBALS['wgFoxwayTime'] += microtime(true) - self::$startTime; + \Foxway\Runtime::$time += microtime(true) - self::$startTime; return \UtfNormal::cleanUp($return); } @@ -110,7 +110,7 @@ if( \Foxway\Runtime::$allowedNamespaces !== true && empty(\Foxway\Runtime::$allowedNamespaces[$frame->getTitle()->getNamespace()]) ) { return Html::element( 'span', array('class'=>'error'), wfMessage('foxway-disabled-for-namespace', $frame->getTitle()->getNsText())->escaped() ); } - if( $wgFoxway_max_execution_time !== false && $GLOBALS['wgFoxwayTime'] >= $wgFoxway_max_execution_time) { + if( $wgFoxway_max_execution_time !== false && \Foxway\Runtime::$time >= $wgFoxway_max_execution_time) { return Html::element( 'span', array('class'=>'error'), wfMessage( 'foxway-php-fatal-error-max-execution-time' ) ->numParams( $wgFoxway_max_execution_time ) diff --git a/Settings.php b/Settings.php index 0527d31..9d5b44c 100644 --- a/Settings.php +++ b/Settings.php @@ -38,159 +38,17 @@ */ // Foxway\Runtime::$allowedNamespaces = true; // true by default -Foxway\Runtime::$functions = array_merge( Foxway\Runtime::$functions - , include __DIR__ . '/includes/functions/strings.php' // String Functions @see http://php.net/manual/en/ref.strings.php - , include __DIR__ . '/includes/functions/array.php' // Array Functions @see http://www.php.net/manual/en/ref.array.php - , include __DIR__ . '/includes/functions/math.php' // Math Functions @see http://www.php.net/manual/en/ref.math.php - , include __DIR__ . '/includes/functions/var.php' // Variable handling Functions @see http://www.php.net/manual/en/ref.var.php - , include __DIR__ . '/includes/functions/pcre.php' // PCRE Functions @see http://www.php.net/manual/en/ref.pcre.php +Foxway\Runtime::$functions = array_merge( + include __DIR__ . '/includes/functions/strings.php', // String Functions @see http://php.net/manual/en/ref.strings.php + include __DIR__ . '/includes/functions/array.php', // Array Functions @see http://www.php.net/manual/en/ref.array.php + include __DIR__ . '/includes/functions/math.php', // Math Functions @see http://www.php.net/manual/en/ref.math.php + include __DIR__ . '/includes/functions/var.php', // Variable handling Functions @see http://www.php.net/manual/en/ref.var.php + include __DIR__ . '/includes/functions/pcre.php', // PCRE Functions @see http://www.php.net/manual/en/ref.pcre.php + Foxway\Runtime::$functions ); -$wgFoxwayAllowedPHPConstants = array( - 'CASE_UPPER', - 'CASE_LOWER', - 'SORT_ASC', - 'SORT_DESC', - 'SORT_REGULAR', - 'SORT_NUMERIC', - 'SORT_STRING', - 'SORT_LOCALE_STRING', - 'SORT_NATURAL', // PHP >= 5.4.0 - 'SORT_FLAG_CASE', // PHP >= 5.4.0 - 'COUNT_RECURSIVE', - 'CRYPT_STD_DES', - 'CRYPT_EXT_DES', - 'CRYPT_MD5', - 'CRYPT_BLOWFISH', - 'CRYPT_SHA256', - 'CRYPT_SHA512', - 'ENT_COMPAT', - 'ENT_QUOTES', - 'ENT_NOQUOTES', - 'ENT_HTML401', // PHP >= 5.4.0 - 'ENT_XML1', // PHP >= 5.4.0 - 'ENT_XHTML', // PHP >= 5.4.0 - 'ENT_HTML5', // PHP >= 5.4.0 - 'ENT_IGNORE', - 'ENT_SUBSTITUTE', // PHP >= 5.4.0 - 'ENT_DISALLOWED', // PHP >= 5.4.0 - 'STR_PAD_RIGHT', - 'STR_PAD_LEFT', - 'STR_PAD_BOTH', - 'ABDAY_1', - 'ABDAY_2', - 'ABDAY_3', - 'ABDAY_4', - 'ABDAY_5', - 'ABDAY_6', - 'ABDAY_7', - 'DAY_1', - 'DAY_2', - 'DAY_3', - 'DAY_4', - 'DAY_5', - 'DAY_6', - 'DAY_7', - 'ABMON_1', - 'ABMON_2', - 'ABMON_3', - 'ABMON_4', - 'ABMON_5', - 'ABMON_6', - 'ABMON_7', - 'ABMON_8', - 'ABMON_9', - 'ABMON_10', - 'ABMON_11', - 'ABMON_12', - 'MON_1', - 'MON_2', - 'MON_3', - 'MON_4', - 'MON_5', - 'MON_6', - 'MON_7', - 'MON_8', - 'MON_9', - 'MON_10', - 'MON_11', - 'MON_12', - 'AM_STR', - 'PM_STR', - 'D_T_FMT', - 'D_FMT', - 'T_FMT', - 'T_FMT_AMPM', - 'ERA', - 'ERA_YEAR', - 'ERA_D_T_FMT', - 'ERA_D_FMT', - 'ERA_T_FMT', - 'INT_CURR_SYMBOL', - 'CURRENCY_SYMBOL', - 'CRNCYSTR', - 'MON_DECIMAL_POINT', - 'MON_THOUSANDS_SEP', - 'MON_GROUPING', - 'POSITIVE_SIGN', - 'NEGATIVE_SIGN', - 'INT_FRAC_DIGITS', - 'FRAC_DIGITS', - 'P_CS_PRECEDES', - 'P_SEP_BY_SPACE', - 'N_CS_PRECEDES', - 'N_SEP_BY_SPACE', - 'P_SIGN_POSN', - 'N_SIGN_POSN', - 'DECIMAL_POINT', - 'RADIXCHAR', - 'THOUSANDS_SEP', - 'THOUSEP', - 'GROUPING', - 'YESEXPR', - 'NOEXPR', - 'YESSTR', - 'NOSTR', - 'CODESET', - // @see http://www.php.net/manual/en/pcre.constants.php - 'PREG_PATTERN_ORDER', - 'PREG_SET_ORDER', - 'PREG_OFFSET_CAPTURE', - 'PREG_SPLIT_NO_EMPTY', - 'PREG_SPLIT_DELIM_CAPTURE', - 'PREG_SPLIT_OFFSET_CAPTURE', - 'PREG_NO_ERROR', - 'PREG_INTERNAL_ERROR', - 'PREG_BACKTRACK_LIMIT_ERROR', - 'PREG_RECURSION_LIMIT_ERROR', - 'PREG_BAD_UTF8_ERROR', - 'PREG_BAD_UTF8_OFFSET_ERROR', - 'PCRE_VERSION', - 'PREG_GREP_INVERT', - // @see http://www.php.net/manual/en/math.constants.php - 'M_PI', - 'M_E', - 'M_LOG2E', - 'M_LOG10E', - 'M_LN2', - 'M_LN10', - 'M_PI_2', - 'M_PI_4', - 'M_1_PI', - 'M_2_PI', - 'M_SQRTPI', - 'M_2_SQRTPI', - 'M_SQRT2', - 'M_SQRT3', - 'M_SQRT1_2', - 'M_LNPI', - 'M_EULER', - 'PHP_ROUND_HALF_UP', - 'PHP_ROUND_HALF_DOWN', - 'PHP_ROUND_HALF_EVEN', - 'PHP_ROUND_HALF_ODD', - 'NAN', - 'INF', - 'PHP_INT_MAX', - 'PHP_INT_SIZE', + +Foxway\Runtime::$constants = array_merge( + include __DIR__ . '/includes/constants.php', + Foxway\Runtime::$constants ); diff --git a/includes/Compiler.php b/includes/Compiler.php index cdb3ec0..0a5437d 100644 --- a/includes/Compiler.php +++ b/includes/Compiler.php @@ -465,7 +465,7 @@ if( !isset($operator) ) { $needOperator = true; } // Example: $foo[] // break is not necessary here case ')': - if( $parentFlags & FOXWAY_ALLOW_COMMA_AT_END_PARENTHES ) { $needOperator = true; } + if( !$needOperator && !isset($operator) && $parentFlags & FOXWAY_THIS_IS_FUNCTION ) { $needOperator = true; } // break is not necessary here case ',': case ';': @@ -572,12 +572,11 @@ $stack[] = &$operator; array_shift($needParams); - list( $tmp, $math ) = $memory[0]; + list( $tmp, $math ) = array_shift($memory); $s = self::mergeStackAndMath($tmp, $math); if( $s ) { $stack = array_merge( $s, $stack ); } - array_shift($memory); } $parentLevel--; @@ -639,8 +638,6 @@ $needParams[0][FOXWAY_STACK_PARAM][] = &$operator; $parentFlags = array_pop($parentheses); - //list( $tmp, $math ) = array_shift($memory); // restore $stack, $math - //$s = self::mergeStackAndMath($tmp, $math); list( $s ) = array_shift( $memory ); // restore $stack if( $s ) { $stack = array_merge( $s, $stack ); @@ -648,6 +645,31 @@ $stack[] = array_shift($needParams); }elseif( $parentFlags & FOXWAY_EXPECT_RESULT_AS_PARAM ) { // for operator T_CONTINUE $needParams[0][FOXWAY_STACK_PARAM] = &$operator[FOXWAY_STACK_RESULT]; + }elseif( $parentFlags & FOXWAY_THIS_IS_FUNCTION ) { // for operator T_PRINT + $needParams[0][FOXWAY_STACK_PARAM] = &$operator[FOXWAY_STACK_RESULT]; + unset($operator); + // Save result of T_PRINT to $lastValue + if( $parentFlags & FOXWAY_NEED_RESTORE_RIGHT_OPERATORS ) { // Need restore right operators + $tmp = array_pop( $memOperators ); // restore right operators to $tmp + $tmp[0][FOXWAY_STACK_PARAM_2] = &$needParams[0][FOXWAY_STACK_RESULT]; // Set parents result as param to right operators + $k = array_keys($tmp); + $lk = array_pop( $k ); // Get key of last right operator + $lastValue = &$tmp[$lk]; // Set $lastValue as link to last right operator + $stack = array_merge($stack, $tmp); // Push right operators to stack + unset($tmp); + }else{ + $lastValue = &$needParams[0]; // restore T_PRINT as value + } + array_shift($needParams); + if( $parentFlags & FOXWAY_NEED_RESTORE_OPERATOR ) { // Restore $operator if necessary + $operator = array_pop( $memOperators ); + } + list( $s, $math ) = array_pop($memory); // restore $stack, $math + if( $s ) { + $stack = array_merge( $stack, $s ); + } + $parentFlags = array_pop($parentheses); + goto closeoperator; } //$ifOperators = array(); @@ -783,25 +805,8 @@ $parentheses[] = FOXWAY_EXPECT_START_COMMAND | FOXWAY_EXPECT_SEMICOLON | FOXWAY_EXPECT_DO_TRUE_STACK; $parentheses[] = FOXWAY_EXPECT_RESULT_AS_PARAM; $parentFlags = FOXWAY_EXPECT_PARENTHES_CLOSE; - for( $index++; $index < $countTokens; $index++ ){ // go to '(' - $token = &$tokens[$index]; - if ( is_string($token) ) { - $id = $token; - } else { - list($id, $text, $tokenLine) = $token; - } - switch ($id) { - case T_COMMENT: - case T_DOC_COMMENT: - case T_WHITESPACE: - break; // ignore it - case '(': - break 3; // if ( - default: - throw new ExceptionFoxway($id, FOXWAY_PHP_SYNTAX_ERROR_UNEXPECTED, $tokenLine); - } - } - throw new ExceptionFoxway('$end', FOXWAY_PHP_SYNTAX_ERROR_UNEXPECTED, $tokenLine); + + self::getNextToken( $tokens, $index, $countTokens, $tokenLine, array('(') ); break; case T_ARRAY: // array if( $needOperator ) { throw new ExceptionFoxway($id, FOXWAY_PHP_SYNTAX_ERROR_UNEXPECTED, $tokenLine); } @@ -819,29 +824,10 @@ $parentLevel++; array_unshift( $memory, array($stack, $math) ); // push stack for restore late. Example: echo $a + array - //array_unshift( $memory, array() ); // push empty stak for operators of function params. Example: $foo=array(1+2,3+4); $stack = array(); $math = array(); - for( $index++; $index < $countTokens; $index++ ){ // go to '(' - $token = &$tokens[$index]; - if ( is_string($token) ) { - $id = $token; - } else { - list($id, $text, $tokenLine) = $token; - } - switch ($id) { - case T_COMMENT: - case T_DOC_COMMENT: - case T_WHITESPACE: - break; // ignore it - case '(': - break 3; // array ( - default: - throw new ExceptionFoxway($id, FOXWAY_PHP_SYNTAX_ERROR_UNEXPECTED, $tokenLine); - } - } - throw new ExceptionFoxway('$end', FOXWAY_PHP_SYNTAX_ERROR_UNEXPECTED, $tokenLine); + self::getNextToken( $tokens, $index, $countTokens, $tokenLine, array('(') ); break; case '~': case '!': @@ -1019,11 +1005,35 @@ }while( ',' == self::getNextToken( $tokens, $index, $countTokens, $tokenLine, array(',', ';') ) ); $bytecode[][] = $tmp; break; + case T_PRINT: // print + if( $needOperator ) { throw new ExceptionFoxway($id, FOXWAY_PHP_SYNTAX_ERROR_UNEXPECTED, $tokenLine); } + $parentheses[] = $parentFlags; + $parentFlags = FOXWAY_EXPECT_SEMICOLON | FOXWAY_THIS_IS_FUNCTION; + + array_unshift( $needParams, array(FOXWAY_STACK_COMMAND=>T_PRINT, FOXWAY_STACK_RESULT=>1, FOXWAY_STACK_TOKEN_LINE=>$tokenLine) ); + $stack[] = &$needParams[0]; + + if( isset($operator) ) { // Operator exists. Examples: echo 1+print + $memOperators[] = &$operator; // push $operator temporarily without PARAM_2 + unset($operator); + $parentFlags |= FOXWAY_NEED_RESTORE_OPERATOR; + } + if( $rightOperators ) { // right operator was used, example: echo -print + $memOperators[] = $rightOperators; // push $rightOperators for restore later + $rightOperators = array(); + $parentFlags |= FOXWAY_NEED_RESTORE_RIGHT_OPERATORS; + unset($lastValue); + } + + $memory[] = array($stack, $math); // push stack for restore late. Example: echo $a + array + $stack = array(); + $math = array(); + break; case T_EMPTY: case T_ISSET: case T_UNSET: case T_LIST: - case T_PRINT: + // @todo default : throw new ExceptionFoxway($id, FOXWAY_PHP_SYNTAX_ERROR_UNEXPECTED, $tokenLine); diff --git a/includes/Runtime.php b/includes/Runtime.php index 6c28d81..dab0d0e 100644 --- a/includes/Runtime.php +++ b/includes/Runtime.php @@ -26,6 +26,7 @@ class Runtime { static public $functions=array(); + static public $constants=array(); static public $allowedNamespaces = true; static public $time = 0; protected $lastCommand = false; @@ -724,6 +725,9 @@ $return[] = $v[FOXWAY_STACK_RESULT]; } break; + case T_PRINT: + $return[] = $value[FOXWAY_STACK_PARAM]; + break; case '~': $value[FOXWAY_STACK_RESULT] = ~$value[FOXWAY_STACK_PARAM_2]; break; @@ -869,10 +873,11 @@ } break; case T_STRING: + $name = $value[FOXWAY_STACK_PARAM_2]; if( isset($value[FOXWAY_STACK_PARAM]) ) { // This is function or object if( is_array($value[FOXWAY_STACK_PARAM]) ) { // This is function - if( isset( self::$functions[ $value[FOXWAY_STACK_PARAM_2] ] ) ) { - $function = &self::$functions[ $value[FOXWAY_STACK_PARAM_2] ]; + if( isset( self::$functions[$name] ) ) { + $function = &self::$functions[$name]; $param = array(); foreach($value[FOXWAY_STACK_PARAM] as $val) { if( $val[FOXWAY_STACK_COMMAND] == T_VARIABLE ) { // Example $foo @@ -912,7 +917,7 @@ } } } - throw new ExceptionFoxway($value[FOXWAY_STACK_PARAM_2], FOXWAY_PHP_WARNING_WRONG_PARAMETER_COUNT, $value[FOXWAY_STACK_TOKEN_LINE]); + throw new ExceptionFoxway($name, FOXWAY_PHP_WARNING_WRONG_PARAMETER_COUNT, $value[FOXWAY_STACK_TOKEN_LINE]); } while(false); if( is_callable($function) ) { @@ -929,22 +934,27 @@ } catch ( ExceptionFoxway $e ) { // @todo // $e add $value[FOXWAY_STACK_TOKEN_LINE] - // $e add $value[FOXWAY_STACK_PARAM_2] + // $e add $name throw $e; } catch (Exception $e) { - throw new ExceptionFoxway($value[FOXWAY_STACK_PARAM_2], FOXWAY_PHP_FATAL_ERROR_CALL_TO_FUNCTION, $value[FOXWAY_STACK_TOKEN_LINE]); + throw new ExceptionFoxway($name, FOXWAY_PHP_FATAL_ERROR_CALL_TO_FUNCTION, $value[FOXWAY_STACK_TOKEN_LINE]); } }else{ - throw new ExceptionFoxway($value[FOXWAY_STACK_PARAM_2], FOXWAY_PHP_FATAL_UNABLE_CALL_TO_FUNCTION, $value[FOXWAY_STACK_TOKEN_LINE]); + throw new ExceptionFoxway($name, FOXWAY_PHP_FATAL_UNABLE_CALL_TO_FUNCTION, $value[FOXWAY_STACK_TOKEN_LINE]); } }else{ - throw new ExceptionFoxway($value[FOXWAY_STACK_PARAM_2], FOXWAY_PHP_FATAL_CALL_TO_UNDEFINED_FUNCTION, $value[FOXWAY_STACK_TOKEN_LINE]); + throw new ExceptionFoxway($name, FOXWAY_PHP_FATAL_CALL_TO_UNDEFINED_FUNCTION, $value[FOXWAY_STACK_TOKEN_LINE]); } }else{ // This is object // @todo } }else{ // This is constant - // @todo + if( isset(self::$constants[$name]) ) { + $value[FOXWAY_STACK_RESULT] = is_callable(self::$constants[$name]) ? self::$constants[$name]() :self::$constants[$name]; + }else{ + $value[FOXWAY_STACK_RESULT] = $name; + // @todo send notice undefined constant + } } break; default: diff --git a/includes/constants.php b/includes/constants.php new file mode 100644 index 0000000..24eeac8 --- /dev/null +++ b/includes/constants.php @@ -0,0 +1,159 @@ +<?php +/** + * Definition constants + * @see http://www.php.net/manual/en/ref.pcre.php + */ + +// Check to see if we are being called as an extension or directly +if ( !defined( 'MEDIAWIKI' ) ) { + die( 'This file is an extension to MediaWiki and thus not a valid entry point.' ); +} + +return array( + 'CASE_UPPER' => CASE_UPPER, + 'CASE_LOWER' => CASE_LOWER, + 'SORT_ASC' => SORT_ASC, + 'SORT_DESC' => SORT_DESC, + 'SORT_REGULAR' => SORT_REGULAR, + 'SORT_NUMERIC' => SORT_NUMERIC, + 'SORT_STRING' => SORT_STRING, + 'SORT_LOCALE_STRING' => SORT_LOCALE_STRING, +// @todo 'SORT_NATURAL', // PHP >= 5.4.0 +// @todo 'SORT_FLAG_CASE', // PHP >= 5.4.0 + 'COUNT_RECURSIVE' => COUNT_RECURSIVE, + 'CRYPT_STD_DES' => CRYPT_STD_DES, + 'CRYPT_EXT_DES' => CRYPT_EXT_DES, + 'CRYPT_MD5' => CRYPT_MD5, + 'CRYPT_BLOWFISH' => CRYPT_BLOWFISH, + 'CRYPT_SHA256' => CRYPT_SHA256, + 'CRYPT_SHA512' => CRYPT_SHA512, + 'ENT_COMPAT' => ENT_COMPAT, + 'ENT_QUOTES' => ENT_QUOTES, + 'ENT_NOQUOTES' => ENT_NOQUOTES, +// @tod 'ENT_HTML401', // PHP >= 5.4.0 +// @todo 'ENT_XML1', // PHP >= 5.4.0 +// @todo 'ENT_XHTML', // PHP >= 5.4.0 +// @todo 'ENT_HTML5', // PHP >= 5.4.0 + 'ENT_IGNORE' => ENT_IGNORE, +// @todo 'ENT_SUBSTITUTE', // PHP >= 5.4.0 +// @todo 'ENT_DISALLOWED', // PHP >= 5.4.0 + 'STR_PAD_RIGHT' => STR_PAD_RIGHT, + 'STR_PAD_LEFT' => STR_PAD_LEFT, + 'STR_PAD_BOTH' => STR_PAD_BOTH, + 'ABDAY_1' => ABDAY_1, + 'ABDAY_2' => ABDAY_2, + 'ABDAY_3' => ABDAY_3, + 'ABDAY_4' => ABDAY_4, + 'ABDAY_5' => ABDAY_5, + 'ABDAY_6' => ABDAY_6, + 'ABDAY_7' => ABDAY_7, + 'DAY_1' => DAY_1, + 'DAY_2' => DAY_2, + 'DAY_3' => DAY_3, + 'DAY_4' => DAY_4, + 'DAY_5' => DAY_5, + 'DAY_6' => DAY_6, + 'DAY_7' => DAY_7, + 'ABMON_1' => ABMON_1, + 'ABMON_2' => ABMON_2, + 'ABMON_3' => ABMON_3, + 'ABMON_4' => ABMON_4, + 'ABMON_5' => ABMON_5, + 'ABMON_6' => ABMON_6, + 'ABMON_7' => ABMON_7, + 'ABMON_8' => ABMON_8, + 'ABMON_9' => ABMON_9, + 'ABMON_10' => ABMON_10, + 'ABMON_11' => ABMON_11, + 'ABMON_12' => ABMON_12, + 'MON_1' => MON_1, + 'MON_2' => MON_2, + 'MON_3' => MON_3, + 'MON_4' => MON_4, + 'MON_5' => MON_5, + 'MON_6' => MON_6, + 'MON_7' => MON_7, + 'MON_8' => MON_8, + 'MON_9' => MON_9, + 'MON_10' => MON_10, + 'MON_11' => MON_11, + 'MON_12' => MON_12, + 'AM_STR' => AM_STR, + 'PM_STR' => PM_STR, + 'D_T_FMT' => D_T_FMT, + 'D_FMT' => D_FMT, + 'T_FMT' => T_FMT, + 'T_FMT_AMPM' => T_FMT_AMPM, + 'ERA' => ERA, + 'ERA_YEAR' => ERA_YEAR, + 'ERA_D_T_FMT' => ERA_D_T_FMT, + 'ERA_D_FMT' => ERA_D_FMT, + 'ERA_T_FMT' => ERA_T_FMT, + 'INT_CURR_SYMBOL' => INT_CURR_SYMBOL, + 'CURRENCY_SYMBOL' => CURRENCY_SYMBOL, + 'CRNCYSTR' => CRNCYSTR, + 'MON_DECIMAL_POINT' => MON_DECIMAL_POINT, + 'MON_THOUSANDS_SEP' => MON_THOUSANDS_SEP, + 'MON_GROUPING' => MON_GROUPING, + 'POSITIVE_SIGN' => POSITIVE_SIGN, + 'NEGATIVE_SIGN' => NEGATIVE_SIGN, + 'INT_FRAC_DIGITS' => INT_FRAC_DIGITS, + 'FRAC_DIGITS' => FRAC_DIGITS, + 'P_CS_PRECEDES' => P_CS_PRECEDES, + 'P_SEP_BY_SPACE' => P_SEP_BY_SPACE, + 'N_CS_PRECEDES' => N_CS_PRECEDES, + 'N_SEP_BY_SPACE' => N_SEP_BY_SPACE, + 'P_SIGN_POSN' => P_SIGN_POSN, + 'N_SIGN_POSN' => N_SIGN_POSN, + 'DECIMAL_POINT' => DECIMAL_POINT, + 'RADIXCHAR' => RADIXCHAR, + 'THOUSANDS_SEP' => THOUSANDS_SEP, + 'THOUSEP' => THOUSEP, + 'GROUPING' => GROUPING, + 'YESEXPR' => YESEXPR, + 'NOEXPR' => NOEXPR, + 'YESSTR' => YESSTR, + 'NOSTR' => NOSTR, + 'CODESET' => CODESET, + // @see http://www.php.net/manual/en/pcre.constants.php + 'PREG_PATTERN_ORDER' => PREG_PATTERN_ORDER, + 'PREG_SET_ORDER' => PREG_SET_ORDER, + 'PREG_OFFSET_CAPTURE' => PREG_OFFSET_CAPTURE, + 'PREG_SPLIT_NO_EMPTY' => PREG_SPLIT_NO_EMPTY, + 'PREG_SPLIT_DELIM_CAPTURE' => PREG_SPLIT_DELIM_CAPTURE, + 'PREG_SPLIT_OFFSET_CAPTURE' => PREG_SPLIT_OFFSET_CAPTURE, + 'PREG_NO_ERROR' => PREG_NO_ERROR, + 'PREG_INTERNAL_ERROR' => PREG_INTERNAL_ERROR, + 'PREG_BACKTRACK_LIMIT_ERROR' => PREG_BACKTRACK_LIMIT_ERROR, + 'PREG_RECURSION_LIMIT_ERROR' => PREG_RECURSION_LIMIT_ERROR, + 'PREG_BAD_UTF8_ERROR' => PREG_BAD_UTF8_ERROR, + 'PREG_BAD_UTF8_OFFSET_ERROR' => PREG_BAD_UTF8_OFFSET_ERROR, + 'PCRE_VERSION' => PCRE_VERSION, + 'PREG_GREP_INVERT' => PREG_GREP_INVERT, + // @see http://www.php.net/manual/en/math.constants.php + 'M_PI' => M_PI, + 'M_E' => M_E, + 'M_LOG2E' => M_LOG2E, + 'M_LOG10E' => M_LOG10E, + 'M_LN2' => M_LN2, + 'M_LN10' => M_LN10, + 'M_PI_2' => M_PI_2, + 'M_PI_4' => M_PI_4, + 'M_1_PI' => M_1_PI, + 'M_2_PI' => M_2_PI, + 'M_SQRTPI' => M_SQRTPI, + 'M_2_SQRTPI' => M_2_SQRTPI, + 'M_SQRT2' => M_SQRT2, + 'M_SQRT3' => M_SQRT3, + 'M_SQRT1_2' => M_SQRT1_2, + 'M_LNPI' => M_LNPI, + 'M_EULER' => M_EULER, + 'PHP_ROUND_HALF_UP' => PHP_ROUND_HALF_UP, + 'PHP_ROUND_HALF_DOWN' => PHP_ROUND_HALF_DOWN, + 'PHP_ROUND_HALF_EVEN' => PHP_ROUND_HALF_EVEN, + 'PHP_ROUND_HALF_ODD' => PHP_ROUND_HALF_ODD, + 'NAN' => NAN, + 'INF' => INF, + 'PHP_INT_MAX' => PHP_INT_MAX, + 'PHP_INT_SIZE' => PHP_INT_SIZE, +); diff --git a/includes/functions/pcre.php b/includes/functions/pcre.php index 4cd2b3b..0f74ffa 100644 --- a/includes/functions/pcre.php +++ b/includes/functions/pcre.php @@ -19,7 +19,7 @@ $delimPos = strpos( $regexStarts, $pattern[0] ); if ( $delimPos === false ) { - throw new ExceptionFoxway('preg_replace', FOXWAY_PHP_WARNING_WRONG_DELIMITER ); + throw new Foxway\ExceptionFoxway('preg_replace', FOXWAY_PHP_WARNING_WRONG_DELIMITER ); } $end = $regexEnds[$delimPos]; @@ -28,7 +28,7 @@ while ( !isset( $endPos ) ) { $pos = strpos( $pattern, $end, $pos ); if ( $pos === false ) { - throw new ExceptionFoxway( array('preg_replace', $end), FOXWAY_PHP_WARNING_NO_ENDING_DELIMITER ); + throw new Foxway\ExceptionFoxway( array('preg_replace', $end), FOXWAY_PHP_WARNING_NO_ENDING_DELIMITER ); } $backslashes = 0; for ( $l = $pos - 1; $l >= 0; $l-- ) { @@ -43,7 +43,7 @@ $len = strlen( $endRegex ); for ( $c = 0; $c < $len; $c++ ) { if ( strpos( $regexModifiers, $endRegex[$c] ) === false ) { - throw new ExceptionFoxway( array('preg_replace', $endRegex[$c]), FOXWAY_PHP_WARNING_UNKNOWN_MODIFIER ); + throw new Foxway\Foxway\ExceptionFoxway( array('preg_replace', $endRegex[$c]), FOXWAY_PHP_WARNING_UNKNOWN_MODIFIER ); } } return $startRegex . $endRegex . 'u'; diff --git a/tests/phpunit/includes/RuntimeTest.php b/tests/phpunit/includes/RuntimeTest.php index d1b9c87..cb59312 100644 --- a/tests/phpunit/includes/RuntimeTest.php +++ b/tests/phpunit/includes/RuntimeTest.php @@ -1,13 +1,28 @@ <?php namespace Foxway; -Runtime::$functions = array_merge( Runtime::$functions - , include __DIR__ . '/../../../includes/functions/strings.php' // String Functions @see http://php.net/manual/en/ref.strings.php - , include __DIR__ . '/../../../includes/functions/array.php' // Array Functions @see http://www.php.net/manual/en/ref.array.php - , include __DIR__ . '/../../../includes/functions/math.php' // Math Functions @see http://www.php.net/manual/en/ref.math.php - , include __DIR__ . '/../../../includes/functions/var.php' // Variable handling Functions @see http://www.php.net/manual/en/ref.var.php - , include __DIR__ . '/../../../includes/functions/pcre.php' // PCRE Functions @see http://www.php.net/manual/en/ref.pcre.php +//$ttt = microtime(true); +//Runtime::$functions = Runtime::$functions + +// ( include __DIR__ . '/../../../includes/functions/strings.php' ) + // String Functions @see http://php.net/manual/en/ref.strings.php +// ( include __DIR__ . '/../../../includes/functions/array.php' ) + // Array Functions @see http://www.php.net/manual/en/ref.array.php +// ( include __DIR__ . '/../../../includes/functions/math.php' ) + // Math Functions @see http://www.php.net/manual/en/ref.math.php +// ( include __DIR__ . '/../../../includes/functions/var.php' ) + // Variable handling Functions @see http://www.php.net/manual/en/ref.var.php +// ( include __DIR__ . '/../../../includes/functions/pcre.php' ); // PCRE Functions @see http://www.php.net/manual/en/ref.pcre.php + +Runtime::$functions = array_merge( + include __DIR__ . '/../../../includes/functions/strings.php', // String Functions @see http://php.net/manual/en/ref.strings.php + include __DIR__ . '/../../../includes/functions/array.php', // Array Functions @see http://www.php.net/manual/en/ref.array.php + include __DIR__ . '/../../../includes/functions/math.php', // Math Functions @see http://www.php.net/manual/en/ref.math.php + include __DIR__ . '/../../../includes/functions/var.php', // Variable handling Functions @see http://www.php.net/manual/en/ref.var.php + include __DIR__ . '/../../../includes/functions/pcre.php', // PCRE Functions @see http://www.php.net/manual/en/ref.pcre.php + Runtime::$functions ); + +Runtime::$constants = array_merge( + include __DIR__ . '/../../../includes/constants.php', + Runtime::$constants +); +//echo microtime(true) - $ttt, "\n\n"; // 0.004227876663208 class RuntimeTest extends \PHPUnit_Framework_TestCase { @@ -1643,6 +1658,61 @@ ); } + public function testRun_print_1() { + $this->assertEquals( + Runtime::runSource('print "hello";'), + array('hello') + ); + } + public function testRun_print_2() { + $this->assertEquals( + Runtime::runSource('print("Hello World");'), + array('Hello World') + ); + } + public function testRun_print_3() { + $this->assertEquals( + Runtime::runSource('$foo = "foobar"; print $foo;'), + array('foobar') + ); + } + public function testRun_print_4() { + $this->assertEquals( + Runtime::runSource('print "foo is $foo";'), + array('foo is foobar') + ); + } + public function testRun_echo_print_1() { + $this->assertEquals( + Runtime::runSource('echo print $foo;'), + array('foobar', 1) + ); + } + public function testRun_echo_print_2() { + $this->assertEquals( + Runtime::runSource('echo -print $foo;'), + array('foobar', -1) + ); + } + public function testRun_echo_print_3() { + $this->assertEquals( + Runtime::runSource('echo 2+print $foo;'), + array('foobar', 3) + ); + } + public function testRun_echo_print_4() { + $this->assertEquals( + Runtime::runSource('echo 5*2+print $foo;'), + array('foobar', 11) + ); + } + public function testRun_echo_print_5() { + $this->assertEquals( + Runtime::runSource('echo 5+2*print $foo;'), + array('foobar', 7) + ); + } + public function testRun_while_1() { $this->assertEquals( Runtime::runSource('$i=1; while( $i <= 3 ) { echo $i++; }'), -- To view, visit https://gerrit.wikimedia.org/r/93446 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I3cef8f07f5fe3f541dc819f9e449597483f50c23 Gerrit-PatchSet: 2 Gerrit-Project: mediawiki/extensions/Foxway Gerrit-Branch: develop Gerrit-Owner: Pastakhov <pastak...@yandex.ru> Gerrit-Reviewer: Pastakhov <pastak...@yandex.ru> Gerrit-Reviewer: jenkins-bot _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits