|
@@ 102-121 (lines=20) @@
|
| 99 |
|
* @return int |
| 100 |
|
* @throws \Exception |
| 101 |
|
*/ |
| 102 |
|
protected function append($dsl, $context) |
| 103 |
|
{ |
| 104 |
|
if (!isset($dsl['file']) || !isset($dsl['body'])) { |
| 105 |
|
throw new \Exception("Can not append to file: name or body missing"); |
| 106 |
|
} |
| 107 |
|
|
| 108 |
|
if (is_string($dsl['body'])) { |
| 109 |
|
$contents = $this->resolveReferencesInText($dsl['body']); |
| 110 |
|
} else { |
| 111 |
|
throw new \Exception("Can not append to file: body tag must be a string"); |
| 112 |
|
} |
| 113 |
|
|
| 114 |
|
$fileName = $this->referenceResolver->resolveReference($dsl['file']); |
| 115 |
|
|
| 116 |
|
$return = file_put_contents($fileName, $contents, FILE_APPEND); |
| 117 |
|
|
| 118 |
|
$this->setReferences($fileName, $dsl); |
| 119 |
|
|
| 120 |
|
return $return; |
| 121 |
|
} |
| 122 |
|
|
| 123 |
|
/** |
| 124 |
|
* @param array $dsl |
|
@@ 129-150 (lines=22) @@
|
| 126 |
|
* @return int |
| 127 |
|
* @throws \Exception |
| 128 |
|
*/ |
| 129 |
|
protected function prepend($dsl, $context) |
| 130 |
|
{ |
| 131 |
|
if (!isset($dsl['file']) || !isset($dsl['body'])) { |
| 132 |
|
throw new \Exception("Can not prepend to file: name or body missing"); |
| 133 |
|
} |
| 134 |
|
|
| 135 |
|
if (is_string($dsl['body'])) { |
| 136 |
|
$contents = $this->resolveReferencesInText($dsl['body']); |
| 137 |
|
} else { |
| 138 |
|
throw new \Exception("Can not append to file: body tag must be a string"); |
| 139 |
|
} |
| 140 |
|
|
| 141 |
|
$fileName = $this->referenceResolver->resolveReference($dsl['file']); |
| 142 |
|
|
| 143 |
|
$contents .= file_get_contents($fileName); |
| 144 |
|
|
| 145 |
|
$return = file_put_contents($fileName, $contents); |
| 146 |
|
|
| 147 |
|
$this->setReferences($fileName, $dsl); |
| 148 |
|
|
| 149 |
|
return $return; |
| 150 |
|
} |
| 151 |
|
|
| 152 |
|
/** |
| 153 |
|
* @param array $dsl |