|
@@ 102-126 (lines=25) @@
|
| 99 |
|
* @return true |
| 100 |
|
* @throws \Exception |
| 101 |
|
*/ |
| 102 |
|
protected function copy($dsl, $context) |
| 103 |
|
{ |
| 104 |
|
if (!isset($dsl['from']) || !isset($dsl['to'])) { |
| 105 |
|
throw new \Exception("Can not copy file: from or to missing"); |
| 106 |
|
} |
| 107 |
|
|
| 108 |
|
$fileName = $this->referenceResolver->resolveReference($dsl['from']); |
| 109 |
|
if (!file_exists($fileName)) { |
| 110 |
|
throw new \Exception("Can not copy file '$fileName': file missing"); |
| 111 |
|
} |
| 112 |
|
|
| 113 |
|
$this->setReferences($fileName, $dsl); |
| 114 |
|
|
| 115 |
|
$to = $this->referenceResolver->resolveReference($dsl['to']); |
| 116 |
|
$overwrite = isset($dsl['overwrite']) ? $overwrite = $dsl['overwrite'] : false; |
| 117 |
|
if (!$overwrite && file_exists($to)) { |
| 118 |
|
throw new \Exception("Can not copy file to '$to: file already exists"); |
| 119 |
|
} |
| 120 |
|
|
| 121 |
|
if (!copy($fileName, $to)) { |
| 122 |
|
throw new \Exception("Can not copy file '$fileName' to '$to': operation failed"); |
| 123 |
|
} |
| 124 |
|
|
| 125 |
|
return true; |
| 126 |
|
} |
| 127 |
|
|
| 128 |
|
/** |
| 129 |
|
* @param array $dsl |
|
@@ 134-158 (lines=25) @@
|
| 131 |
|
* @return true |
| 132 |
|
* @throws \Exception |
| 133 |
|
*/ |
| 134 |
|
protected function move($dsl, $context) |
| 135 |
|
{ |
| 136 |
|
if (!isset($dsl['from']) || !isset($dsl['to'])) { |
| 137 |
|
throw new \Exception("Can not move file: from or to missing"); |
| 138 |
|
} |
| 139 |
|
|
| 140 |
|
$fileName = $this->referenceResolver->resolveReference($dsl['from']); |
| 141 |
|
if (!file_exists($fileName)) { |
| 142 |
|
throw new \Exception("Can not move file '$fileName': file missing"); |
| 143 |
|
} |
| 144 |
|
|
| 145 |
|
$this->setReferences($fileName, $dsl); |
| 146 |
|
|
| 147 |
|
$to = $this->referenceResolver->resolveReference($dsl['to']); |
| 148 |
|
$overwrite = isset($dsl['overwrite']) ? $overwrite = $dsl['overwrite'] : false; |
| 149 |
|
if (!$overwrite && file_exists($to)) { |
| 150 |
|
throw new \Exception("Can not move to '$to': file already exists"); |
| 151 |
|
} |
| 152 |
|
|
| 153 |
|
if (!rename($fileName, $to)) { |
| 154 |
|
throw new \Exception("Can not move file '$fileName': operation failed"); |
| 155 |
|
} |
| 156 |
|
|
| 157 |
|
return true; |
| 158 |
|
} |
| 159 |
|
|
| 160 |
|
/** |
| 161 |
|
* @param array $dsl |