|
@@ 158-182 (lines=25) @@
|
| 155 |
|
* @return true |
| 156 |
|
* @throws \Exception |
| 157 |
|
*/ |
| 158 |
|
protected function copy($dsl, $context) |
| 159 |
|
{ |
| 160 |
|
if (!isset($dsl['from']) || !isset($dsl['to'])) { |
| 161 |
|
throw new \Exception("Can not copy file: from or to missing"); |
| 162 |
|
} |
| 163 |
|
|
| 164 |
|
$fileName = $this->referenceResolver->resolveReference($dsl['from']); |
| 165 |
|
if (!file_exists($fileName)) { |
| 166 |
|
throw new \Exception("Can not copy file '$fileName': file missing"); |
| 167 |
|
} |
| 168 |
|
|
| 169 |
|
$this->setReferences($fileName, $dsl); |
| 170 |
|
|
| 171 |
|
$to = $this->referenceResolver->resolveReference($dsl['to']); |
| 172 |
|
$overwrite = isset($dsl['overwrite']) ? $overwrite = $dsl['overwrite'] : false; |
| 173 |
|
if (!$overwrite && file_exists($to)) { |
| 174 |
|
throw new \Exception("Can not copy file to '$to: file already exists"); |
| 175 |
|
} |
| 176 |
|
|
| 177 |
|
if (!copy($fileName, $to)) { |
| 178 |
|
throw new \Exception("Can not copy file '$fileName' to '$to': operation failed"); |
| 179 |
|
} |
| 180 |
|
|
| 181 |
|
return true; |
| 182 |
|
} |
| 183 |
|
|
| 184 |
|
/** |
| 185 |
|
* @param array $dsl |
|
@@ 190-214 (lines=25) @@
|
| 187 |
|
* @return true |
| 188 |
|
* @throws \Exception |
| 189 |
|
*/ |
| 190 |
|
protected function move($dsl, $context) |
| 191 |
|
{ |
| 192 |
|
if (!isset($dsl['from']) || !isset($dsl['to'])) { |
| 193 |
|
throw new \Exception("Can not move file: from or to missing"); |
| 194 |
|
} |
| 195 |
|
|
| 196 |
|
$fileName = $this->referenceResolver->resolveReference($dsl['from']); |
| 197 |
|
if (!file_exists($fileName)) { |
| 198 |
|
throw new \Exception("Can not move file '$fileName': file missing"); |
| 199 |
|
} |
| 200 |
|
|
| 201 |
|
$this->setReferences($fileName, $dsl); |
| 202 |
|
|
| 203 |
|
$to = $this->referenceResolver->resolveReference($dsl['to']); |
| 204 |
|
$overwrite = isset($dsl['overwrite']) ? $overwrite = $dsl['overwrite'] : false; |
| 205 |
|
if (!$overwrite && file_exists($to)) { |
| 206 |
|
throw new \Exception("Can not move to '$to': file already exists"); |
| 207 |
|
} |
| 208 |
|
|
| 209 |
|
if (!rename($fileName, $to)) { |
| 210 |
|
throw new \Exception("Can not move file '$fileName': operation failed"); |
| 211 |
|
} |
| 212 |
|
|
| 213 |
|
return true; |
| 214 |
|
} |
| 215 |
|
|
| 216 |
|
/** |
| 217 |
|
* @param array $dsl |