You are here

protected function StaticGenerator::copyPath in Tome 8

Attempts to copy a path from the file system.

Parameters

string $path: The path.

string $destination: The destination.

Return value

bool TRUE if $path exists and was copied to $destination, FALSE otherwise.

2 calls to StaticGenerator::copyPath()
StaticGenerator::exportPaths in modules/tome_static/src/StaticGenerator.php
Exports multiple paths.
StaticGenerator::requestPath in modules/tome_static/src/StaticGenerator.php
Requests and exports a given path.

File

modules/tome_static/src/StaticGenerator.php, line 520

Class

StaticGenerator
Handles static site generation.

Namespace

Drupal\tome_static

Code

protected function copyPath($path, $destination) {
  $path = urldecode($path);
  $base_path = base_path();
  if ($base_path !== '/') {
    $base_path = ltrim($base_path, '/');
    $pattern = '|^' . preg_quote($base_path, '|') . '|';
    $path = preg_replace($pattern, '', $path);
  }
  if (file_exists($path)) {
    $directory = dirname($destination);
    $this->fileSystem
      ->prepareDirectory($directory, FileSystemInterface::CREATE_DIRECTORY);
    try {
      $this->fileSystem
        ->copy($path, $destination, FileSystemInterface::CREATE_DIRECTORY);
    } catch (FileWriteException $exception) {
      return FALSE;
    }
    return TRUE;
  }
  return FALSE;
}