original_string: public static function copy($source, $target, $ignore = null)
      {
          $source = rtrim($source, '\\/');
          $target = rtrim($target, '\\/');
  
          if (!is_dir($source)) {
              throw new \RuntimeException('Cannot copy non-existing folder.');
          }
  
          // Make sure that path to the target exists before copying.
          self::create($target);
  
          $success = true;
  
          // Go through all sub-directories and copy everything.
          $files = self::all($source);
          foreach ($files as $file) {
              if ($ignore && preg_match($ignore, $file)) {
                  continue;
              }
              $src = $source .'/'. $file;
              $dst = $target .'/'. $file;
  
              if (is_dir($src)) {
                  // Create current directory (if it doesn't exist).
                  if (!is_dir($dst)) {
                      $success &= @mkdir($dst, 0777, true);
                  }
              } else {
                  // Or copy current file.
                  $success &= @copy($src, $dst);
              }
          }
  
          if (!$success) {
              $error = error_get_last();
              throw new \RuntimeException($error['message'] ?? 'Unknown error');
          }
  
          // Make sure that the change will be detected when caching.
          @touch(dirname($target));
      }
code: public static function copy($source, $target, $ignore = null)
      {
          $source = rtrim($source, '\\/');
          $target = rtrim($target, '\\/');
  
          if (!is_dir($source)) {
              throw new \RuntimeException('Cannot copy non-existing folder.');
          }
  
          // Make sure that path to the target exists before copying.
          self::create($target);
  
          $success = true;
  
          // Go through all sub-directories and copy everything.
          $files = self::all($source);
          foreach ($files as $file) {
              if ($ignore && preg_match($ignore, $file)) {
                  continue;
              }
              $src = $source .'/'. $file;
              $dst = $target .'/'. $file;
  
              if (is_dir($src)) {
                  // Create current directory (if it doesn't exist).
                  if (!is_dir($dst)) {
                      $success &= @mkdir($dst, 0777, true);
                  }
              } else {
                  // Or copy current file.
                  $success &= @copy($src, $dst);
              }
          }
  
          if (!$success) {
              $error = error_get_last();
              throw new \RuntimeException($error['message'] ?? 'Unknown error');
          }
  
          // Make sure that the change will be detected when caching.
          @touch(dirname($target));
      }
code_tokens: public static function copy ( $ source , $ target , $ ignore = null ) { $ source = rtrim ( $ source , '\\/' ) ; $ target = rtrim ( $ target , '\\/' ) ; if ( ! is_dir ( $ source ) ) { throw new \ RuntimeException ( 'Cannot copy non-existing folder.' ) ; } // Make sure that path to the target exists before copying. self :: create ( $ target ) ; $ success = true ; // Go through all sub-directories and copy everything. $ files = self :: all ( $ source ) ; foreach ( $ files as $ file ) { if ( $ ignore && preg_match ( $ ignore , $ file ) ) { continue ; } $ src = $ source . '/' . $ file ; $ dst = $ target . '/' . $ file ; if ( is_dir ( $ src ) ) { // Create current directory (if it doesn't exist). if ( ! is_dir ( $ dst ) ) { $ success &= @ mkdir ( $ dst , 0777 , true ) ; } } else { // Or copy current file. $ success &= @ copy ( $ src , $ dst ) ; } } if ( ! $ success ) { $ error = error_get_last ( ) ; throw new \ RuntimeException ( $ error [ 'message' ] ?? 'Unknown error' ) ; } // Make sure that the change will be detected when caching. @ touch ( dirname ( $ target ) ) ; }
docstring: Recursively copy directory in filesystem.
  
  @param  string $source
  @param  string $target
  @param  string $ignore  Ignore files matching pattern (regular expression).
  @throws \RuntimeException
docstring_tokens: Recursively copy directory in filesystem .