Platformsh\Cli\Helper\FilesystemHelper::copyAll PHP Method

copyAll() public method

Copy all files and folders between directories.
public copyAll ( string $source, string $destination, array $skip = ['.git', '.DS_Store'], boolean $override = false )
$source string
$destination string
$skip array
$override boolean
    public function copyAll($source, $destination, array $skip = ['.git', '.DS_Store'], $override = false)
    {
        if (is_dir($source) && !is_dir($destination)) {
            if (!mkdir($destination, 0755, true)) {
                throw new \RuntimeException("Failed to create directory: " . $destination);
            }
        }
        if (is_dir($source)) {
            // Prevent infinite recursion when the destination is inside the
            // source.
            if (strpos($destination, $source) === 0) {
                $relative = str_replace($source, '', $destination);
                $parts = explode('/', ltrim($relative, '/'), 2);
                $skip[] = $parts[0];
            }
            $sourceDirectory = opendir($source);
            while ($file = readdir($sourceDirectory)) {
                // Skip symlinks, '.' and '..', and files in $skip.
                if ($file === '.' || $file === '..' || $this->inBlacklist($file, $skip) || is_link($source . '/' . $file)) {
                    continue;
                } elseif (is_dir($source . '/' . $file)) {
                    $this->copyAll($source . '/' . $file, $destination . '/' . $file, $skip, $override);
                } elseif (is_file($source . '/' . $file)) {
                    $this->fs->copy($source . '/' . $file, $destination . '/' . $file, $override);
                }
            }
            closedir($sourceDirectory);
        } else {
            $this->fs->copy($source, $destination, $override);
        }
    }

Usage Example

 /**
  * Test FilesystemHelper::copy().
  */
 public function testCopy()
 {
     $source = $this->tempDir(true);
     $destination = $this->tempDir();
     // Copy files.
     $this->filesystemHelper->copyAll($source, $destination);
     // Check that they have been copied.
     $this->assertFileExists($destination . '/test-file');
     $this->assertFileExists($destination . '/test-dir/test-file');
 }
All Usage Examples Of Platformsh\Cli\Helper\FilesystemHelper::copyAll