diff options
Diffstat (limited to 'www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Utils/File/ContentsReader.php')
-rw-r--r-- | www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Utils/File/ContentsReader.php | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Utils/File/ContentsReader.php b/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Utils/File/ContentsReader.php new file mode 100644 index 00000000..a9ac8a37 --- /dev/null +++ b/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Utils/File/ContentsReader.php @@ -0,0 +1,43 @@ +<?php + +namespace SMW\Tests\Utils\File; + +use RuntimeException; + +/** + * @license GNU GPL v2+ + * @since 3.0 + * + * @author mwjames + */ +class ContentsReader { + + /** + * @since 3.0 + * + * @param string $file + * + * @return string + */ + public static function readContentsFrom( $file ) { + + $file = str_replace( [ '\\', '/' ], DIRECTORY_SEPARATOR, $file ); + + if ( !is_readable( $file ) ) { + throw new RuntimeException( "Could not open or read: $file" ); + } + + $contents = file_get_contents( $file ); + + // http://php.net/manual/en/function.file-get-contents.php + $contents = mb_convert_encoding( + $contents, + 'UTF-8', + mb_detect_encoding( $contents, 'UTF-8, ISO-8859-1, ISO-8859-2', true ) + ); + + // https://stackoverflow.com/questions/2115549/php-difference-between-r-n-and-n + return str_replace( "\r\n", "\n", $contents ); + } + +} |