forked from php/php-src
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgtCodeSnippet.php
72 lines (57 loc) · 1.36 KB
/
gtCodeSnippet.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
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;
}
}
?>