diff options
author | Lorry Tar Creator <lorry-tar-importer@baserock.org> | 2013-03-14 05:42:27 +0000 |
---|---|---|
committer | <> | 2013-04-03 16:25:08 +0000 |
commit | c4dd7a1a684490673e25aaf4fabec5df138854c4 (patch) | |
tree | 4d57c44caae4480efff02b90b9be86f44bf25409 /scripts/dev/generate-phpt/src/gtCodeSnippet.php | |
download | php2-master.tar.gz |
Imported from /home/lorry/working-area/delta_php2/php-5.4.13.tar.bz2.HEADphp-5.4.13master
Diffstat (limited to 'scripts/dev/generate-phpt/src/gtCodeSnippet.php')
-rw-r--r-- | scripts/dev/generate-phpt/src/gtCodeSnippet.php | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/scripts/dev/generate-phpt/src/gtCodeSnippet.php b/scripts/dev/generate-phpt/src/gtCodeSnippet.php new file mode 100644 index 0000000..220fbdf --- /dev/null +++ b/scripts/dev/generate-phpt/src/gtCodeSnippet.php @@ -0,0 +1,72 @@ +<?php + +/** + * Retrieves code snippets for adding to test cases + * + */ +class gtCodeSnippet +{ + + /** + * get the code snippet and initialise an array with it + * + * @param string $name + * @return array + */ + public static function get($name) { + + $filename = dirname(__FILE__) . '/codeSnippets/' . $name . '.txt'; + + if (!file_exists($filename)) { + throw new LogicException('The code snippet ' . $name . ' does not exist'); + } + + $lines = file($filename); + foreach($lines as $l) { + $array[] = rtrim($l); + } + return $array; + } + + + /** + * Append the code snippet on to an existing array + * + * @param string $name + * @param array $array + * @return array + */ + public static function append($name, $array) { + $filename = dirname(__FILE__) . '/codeSnippets/' . $name . '.txt'; + + if (!file_exists($filename)) { + throw new LogicException('The code snippet ' . $name . ' does not exist'); + } + + $text = file($filename); + foreach ($text as $t) { + $array[] = rtrim($t); + } + + return $array; + } + + + /** + * Appends blank entries on to an array + * + * @param int $numberOfLines + * @param array $array + * @return array + */ + public static function appendBlankLines($numberOfLines, $array) { + + for ($i=0; $i< $numberOfLines; $i++) { + $array[] = ""; + } + + return $array; + } + +} +?>
\ No newline at end of file |