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

copy() public method

Copy a file, if it is newer than the destination.
public copy ( string $source, string $destination, boolean $override = false )
$source string
$destination string
$override boolean
    public function copy($source, $destination, $override = false)
    {
        if (is_dir($destination) && !is_dir($source)) {
            $destination = rtrim($destination, '/') . '/' . basename($source);
        }
        $this->fs->copy($source, $destination, $override);
    }

Usage Example

Esempio n. 1
0
 /**
  * Process the defined special destinations.
  */
 protected function processSpecialDestinations()
 {
     foreach ($this->specialDestinations as $sourcePattern => $relDestination) {
         $matched = glob($this->appRoot . '/' . $sourcePattern, GLOB_NOSORT);
         if (!$matched) {
             continue;
         }
         if ($relDestination === '{webroot}' && $this->buildInPlace) {
             continue;
         }
         // On Platform these replacements would be a bit different.
         $absDestination = str_replace(['{webroot}', '{approot}'], [$this->getWebRoot(), $this->buildDir], $relDestination);
         foreach ($matched as $source) {
             // Ignore the source if it's in ignoredFiles.
             $relSource = str_replace($this->appRoot . '/', '', $source);
             if (in_array($relSource, $this->ignoredFiles)) {
                 continue;
             }
             $destination = $absDestination;
             // Do not overwrite directories with files.
             if (!is_dir($source) && is_dir($destination)) {
                 $destination = $destination . '/' . basename($source);
             }
             // Ignore if source and destination are the same.
             if ($destination === $source) {
                 continue;
             }
             if ($this->copy) {
                 $this->output->writeln("Copying {$relSource} to {$relDestination}");
             } else {
                 $this->output->writeln("Symlinking {$relSource} to {$relDestination}");
             }
             // Delete existing files, emitting a warning.
             if (file_exists($destination)) {
                 $this->output->writeln(sprintf("Overriding existing path '%s' in destination", str_replace($this->buildDir . '/', '', $destination)));
                 $this->fsHelper->remove($destination);
             }
             if ($this->copy) {
                 $this->fsHelper->copy($source, $destination);
             } else {
                 $this->fsHelper->symlink($source, $destination);
             }
         }
     }
 }
All Usage Examples Of Platformsh\Cli\Helper\FilesystemHelper::copy