| @@ 176-201 (lines=26) @@ | ||
| 173 | * @param File $file |
|
| 174 | * @return bool |
|
| 175 | **/ |
|
| 176 | private function createFile(File $file) |
|
| 177 | { |
|
| 178 | // Full path to the file |
|
| 179 | $fullPath = $this->getNodePath($file); |
|
| 180 | ||
| 181 | // Generate contents |
|
| 182 | $contents = $file->getContents($this->getParameters()); |
|
| 183 | ||
| 184 | try { |
|
| 185 | $this->getFilesystem()->dumpFile($fullPath, $contents); |
|
| 186 | if ($file->hasMode()) { |
|
| 187 | $this->getFilesystem()->chmod($fullPath, $file->getMode()); |
|
| 188 | } |
|
| 189 | } catch (FilesystemIOException $filesystemException) { |
|
| 190 | throw new GeneratorException( |
|
| 191 | sprintf( |
|
| 192 | 'Could not generate file "%s"', |
|
| 193 | $fullPath |
|
| 194 | ), |
|
| 195 | 0, |
|
| 196 | $filesystemException |
|
| 197 | ); |
|
| 198 | } |
|
| 199 | ||
| 200 | return $this; |
|
| 201 | } |
|
| 202 | ||
| 203 | /** |
|
| 204 | * Create a directory |
|
| @@ 209-237 (lines=29) @@ | ||
| 206 | * @param Directory $directory |
|
| 207 | * @return Generator |
|
| 208 | **/ |
|
| 209 | private function createDirectory(Directory $directory) |
|
| 210 | { |
|
| 211 | $fullPath = $this->getNodePath($directory); |
|
| 212 | ||
| 213 | // Try to make it |
|
| 214 | try { |
|
| 215 | if ($directory->hasMode()) { |
|
| 216 | $this->getFilesystem()->mkdir($fullPath, $directory->getMode()); |
|
| 217 | } else { |
|
| 218 | $this->getFilesystem()->mkdir($fullPath); |
|
| 219 | } |
|
| 220 | } catch (FilesystemIOException $filesystemException) { |
|
| 221 | throw new GeneratorException( |
|
| 222 | sprintf( |
|
| 223 | 'Could not generate directory "%s"', |
|
| 224 | $this->getNodePath($directory) |
|
| 225 | ), |
|
| 226 | 0, |
|
| 227 | $filesystemException |
|
| 228 | ); |
|
| 229 | } |
|
| 230 | ||
| 231 | // Recurse child nodes |
|
| 232 | foreach ($directory as $node) { |
|
| 233 | $this->createNode($node); |
|
| 234 | } |
|
| 235 | ||
| 236 | return $this; |
|
| 237 | } |
|
| 238 | ||
| 239 | /** |
|
| 240 | * Create a symlink |
|