public static function copy(string $source, string $dest, bool $override = false): void
	{
		if (is_file($source)) {
			self::copyFile($source, $dest, $override);
			return;
		}

		if ( ! is_dir($source)) {
			Helpers::consoleMessage("File or directory '%s' not found.", [$source]);
			return;
		}

		$sourceHandle = opendir($source);

		if ( ! $sourceHandle) {
			throw new SynchronizerException('Failed to copy directory: failed to open source ' . $source);
		}

		while ($file = readdir($sourceHandle)) {
			if (in_array($file, ['.', '..'], true)) {
				continue;
			}

			if (is_dir($source . '/' . $file)) {
				if ( ! file_exists($dest . '/' . $file)) {
					self::createDirectory($dest);
				}

				$file .= '/';
				self::copy($source .  $file, $dest . $file, $override);

			} else {
				$dest = rtrim($dest, '/') . '/';
				$source = rtrim($source, '/') . '/';
				self::copyFile($source . $file, $dest . $file, $override);
			}
		}
	}
public static function copy(string $source, string $dest, bool $override = false): void
	{
		if (is_file($source)) {
			self::copyFile($source, $dest, $override);
			return;
		}

		if ( ! is_dir($source)) {
			Helpers::consoleMessage("File or directory '%s' not found.", [$source]);
			return;
		}

		$sourceHandle = opendir($source);

		if ( ! $sourceHandle) {
			throw new SynchronizerException('Failed to copy directory: failed to open source ' . $source);
		}

		while ($file = readdir($sourceHandle)) {
			if (in_array($file, ['.', '..'], true)) {
				continue;
			}

			if (is_dir($source . '/' . $file)) {
				if ( ! file_exists($dest . '/' . $file)) {
					self::createDirectory($dest);
				}

				$file .= '/';
				self::copy($source .  $file, $dest . $file, $override);

			} else {
				$dest = rtrim($dest, '/') . '/';
				$source = rtrim($source, '/') . '/';
				self::copyFile($source . $file, $dest . $file, $override);
			}
		}
	}
public static function copy ( string $ source , string $ dest , bool $ override = false ) : void { if ( is_file ( $ source ) ) { self :: copyFile ( $ source , $ dest , $ override ) ; return ; } if ( ! is_dir ( $ source ) ) { Helpers :: consoleMessage ( "File or directory '%s' not found." , [ $ source ] ) ; return ; } $ sourceHandle = opendir ( $ source ) ; if ( ! $ sourceHandle ) { throw new SynchronizerException ( 'Failed to copy directory: failed to open source ' . $ source ) ; } while ( $ file = readdir ( $ sourceHandle ) ) { if ( in_array ( $ file , [ '.' , '..' ] , true ) ) { continue ; } if ( is_dir ( $ source . '/' . $ file ) ) { if ( ! file_exists ( $ dest . '/' . $ file ) ) { self :: createDirectory ( $ dest ) ; } $ file .= '/' ; self :: copy ( $ source . $ file , $ dest . $ file , $ override ) ; } else { $ dest = rtrim ( $ dest , '/' ) . '/' ; $ source = rtrim ( $ source , '/' ) . '/' ; self :: copyFile ( $ source . $ file , $ dest . $ file , $ override ) ; } } }
Copies files recursively and automatically creates nested directories
Copies files recursively and automatically creates nested directories