Pastakhov has submitted this change and it was merged. Change subject: Fix dump functions (v 3.8) requere PhpTags >= 5.9 ......................................................................
Fix dump functions (v 3.8) requere PhpTags >= 5.9 Change-Id: I2c267753b1a4397ae62a98018f26e7b4d38f54a2 --- M extension.json M includes/PhpTagsFunc.php M tests/phpunit/PhpTagsFunctions_DateTime_Test.php 3 files changed, 35 insertions(+), 22 deletions(-) Approvals: Pastakhov: Verified; Looks good to me, approved diff --git a/extension.json b/extension.json index 0520d6f..523e342 100644 --- a/extension.json +++ b/extension.json @@ -1,6 +1,6 @@ { "name": "PhpTags Functions", - "version": "3.7.1", + "version": "3.8", "author": "[https://www.mediawiki.org/wiki/User:Pastakhov Pavel Astakhov]", "url": "https://www.mediawiki.org/wiki/Extension:PhpTags_Functions", "descriptionmsg": "phptagsfunctions-desc", diff --git a/includes/PhpTagsFunc.php b/includes/PhpTagsFunc.php index 6a6b7cd..83478ef 100644 --- a/includes/PhpTagsFunc.php +++ b/includes/PhpTagsFunc.php @@ -96,45 +96,59 @@ } public static function f_printf() { - $arguments = func_get_args(); - $ret = call_user_func_array( 'sprintf', $arguments ); + $args = func_get_args(); + $v = array(); + foreach ( $args as $value => $key ) { + $v[$key] = self::getValidDumpValue( $value ); + } + $ret = call_user_func_array( 'sprintf', $v ); return new \PhpTags\outPrint( strlen($ret), $ret, false, false ); } public static function f_vprintf() { - $arguments = func_get_args(); - $ret = call_user_func_array( 'vsprintf', $arguments ); + $args = func_get_args(); + $v = array(); + foreach ( $args as $value => $key ) { + $v[$key] = self::getValidDumpValue( $value ); + } + $ret = call_user_func_array( 'vsprintf', $v ); return new \PhpTags\outPrint( strlen($ret), $ret, false, false ); } public static function f_var_export( $expression, $return = false ) { - if ( $expression instanceof \PhpTags\GenericObject ) { - $expression = $expression->getValue(); - } - $ret = var_export( $expression, true ); + $v = self::getValidDumpValue( $expression ); + $ret = var_export( $v, true ); return $return ? $ret : new \PhpTags\outPrint( null, $ret ); } public static function f_var_dump() { $args = func_get_args(); - foreach ( $args as &$value ) { - if ( $value instanceof \PhpTags\GenericObject ) { - $value = $value->getValue(); - } + $v = array(); + foreach ( $args as $value => $key ) { + $v[$key] = self::getValidDumpValue( $value ); } ob_start(); - call_user_func_array( 'var_dump', $args ); + call_user_func_array( 'var_dump', $v ); return new \PhpTags\outPrint( null, ob_get_clean() ); } public static function f_print_r( $expression, $return = false ) { - if ( $expression instanceof \PhpTags\GenericObject ) { - $expression = $expression->getValue(); - } - $ret = print_r( $expression, true ); + $v = self::getValidDumpValue( $expression ); + $ret = print_r( $v, true ); return $return ? $ret : new \PhpTags\outPrint( true, $ret ); } + private static function getValidDumpValue( $expression ) { + if ( is_object( $expression ) ) { + if ( $expression instanceof \PhpTags\GenericObject ) { + return (array)$expression->getDumpValue(); + } else { + throw new PhpTagsException( PhpTagsException::FATAL_INTERNAL_ERROR ); + } + } + return $expression; + } + /** * @todo remove it for PHP >= 5.4.0 */ diff --git a/tests/phpunit/PhpTagsFunctions_DateTime_Test.php b/tests/phpunit/PhpTagsFunctions_DateTime_Test.php index 2ed3ece..ddada37 100644 --- a/tests/phpunit/PhpTagsFunctions_DateTime_Test.php +++ b/tests/phpunit/PhpTagsFunctions_DateTime_Test.php @@ -93,21 +93,20 @@ public function testRun_DateTime_exception_9() { $this->assertEquals( Runtime::runSource('new DateTime() . 5;', array('Page') ), - array( (string) new \PhpTags\PhpTagsException( \PhpTags\PhpTagsException::NOTICE_OBJECT_CONVERTED, array('DateTime', 'string'), 1, 'Page' ) ) + array( (string) new \PhpTags\PhpTagsException( \PhpTags\PhpTagsException::FATAL_OBJECT_COULD_NOT_BE_CONVERTED, array('DateTime', 'string'), 1, 'Page' ) ) ); } public function testRun_DateTime_exception_10() { $this->assertEquals( Runtime::runSource('5 . new DateInterval("P2Y4DT6H8M");', array('Page') ), - array( (string) new \PhpTags\PhpTagsException( \PhpTags\PhpTagsException::NOTICE_OBJECT_CONVERTED, array('DateInterval', 'string'), 1, 'Page' ) ) + array( (string) new \PhpTags\PhpTagsException( \PhpTags\PhpTagsException::FATAL_OBJECT_COULD_NOT_BE_CONVERTED, array('DateInterval', 'string'), 1, 'Page' ) ) ); } public function testRun_DateTime_exception_11() { $this->assertEquals( Runtime::runSource('new DateTime() . new DateInterval("P2Y4DT6H8M");', array('Page') ), array( - (string) new \PhpTags\PhpTagsException( \PhpTags\PhpTagsException::NOTICE_OBJECT_CONVERTED, array('DateTime', 'string'), 1, 'Page' ), - (string) new \PhpTags\PhpTagsException( \PhpTags\PhpTagsException::NOTICE_OBJECT_CONVERTED, array('DateInterval', 'string'), 1, 'Page' ) + (string) new \PhpTags\PhpTagsException( \PhpTags\PhpTagsException::FATAL_OBJECT_COULD_NOT_BE_CONVERTED, array('DateTime', 'string'), 1, 'Page' ), ) ); } -- To view, visit https://gerrit.wikimedia.org/r/304436 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I2c267753b1a4397ae62a98018f26e7b4d38f54a2 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/PhpTagsFunctions Gerrit-Branch: master Gerrit-Owner: Pastakhov <pastak...@yandex.ru> Gerrit-Reviewer: Pastakhov <pastak...@yandex.ru> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits