Helper method to copy a value from one array to another array.

@param array $target
@param string $key
@param array $source

@return bool
True if the value is set and has been copied, false otherwise.
761120
protected function addIfIsset(array &$target, $key, array $source)
    {
        if (isset($source[$key])) {
            $target[$key] = $source[$key];
            return true;
        }
        return false;
    }
958923
private function deep_copy($source, $target_path)
    {
        // Loop through $source dir.
        $contents = \scandir($source);

        if (empty($contents)) {
            return;
        }

        foreach ($contents as $file) {
            if ('.' === $file || '..' === $file) {
                continue;
            }

            $src_path = \trailingslashit($source) . $file;
            $new_path = \trailingslashit($target_path) . $file;

            if (\is_dir($src_path)) {
                $this->mkdir($new_path);
                $this->deep_copy($src_path, $new_path);
                continue;
            }

            if ($this->file->copy($src_path, $new_path, $this->force)) {
                $this->copied[] = $new_path;
            }
        }
    }
168989
public function cloneProperties($target, $source)
    {
        $this->validaObjects($target, $source);

        $reflection = new \ReflectionClass($target);
        foreach ($reflection->getProperties() as $property) {

            $this->propertyAccessor->setValue(
                $target,
                $property->getName(),
                $this->propertyAccessor->getValue($source, $property->getName())
            );
        }
    }
834749
public function uncompress($source, $target)
    {
        if ($this->zip->open($source, \ZipArchive::CHECKCONS) === false) {
            return false;
        }

        if ($this->zip->extractTo(dirname($target), basename($target)) === false) {
            $this->zip->close();

            return false;
        }

        return $this->zip->close();
    }
59084
protected function _copy($source, $targetDir, $name) {
		$path = $this->_normpath($targetDir.'/'.$name);
		try {
			$this->dropbox->copy($source, $path);
		} catch (Dropbox_Exception $e) {
			return $this->setError('Dropbox error: '.$e->getMessage());
		}
		$this->deltaCheck();
		return true;
	}
590247
private function copyTarget(TranslationValueInterface $source, WritableTranslationValueInterface $target): void
    {
        if (self::DO_NOT_COPY === $this->copyTarget) {
            return;
        }

        if ((($oldValue = $target->getTarget()) === ($newValue = $source->getTarget()))
            || ($target->isTargetEmpty() && $source->isTargetEmpty())
        ) {
            $this->logger->log(
                $this->logLevel,
                '{key}: Target is same, no need to update.',
                ['key' => $target->getKey(), 'old' => $oldValue, 'new' => $newValue]
            );
            return;
        }

        if ((self::COPY_IF_EMPTY === $this->copyTarget) && !$target->isTargetEmpty()) {
            $this->logger->log(
                $this->logLevel,
                '{key}: Target is not empty, no need to update.',
                ['key' => $target->getKey(), 'old' => $oldValue, 'new' => $newValue]
            );

            return;
        }

        $this->logger->log(
            LogLevel::NOTICE,
            '{key}: Updating target value.',
            ['key' => $target->getKey(), 'old' => $oldValue, 'new' => $newValue]
        );

        if ($this->dryRun) {
            return;
        }

        if (null === $value = $source->getTarget()) {
            $target->clearTarget();
            return;
        }
        $target->setTarget($value);
    }
619045
public static function extend($target, $source) 
    {
        switch($target) {
        case 'phpQueryObject':
            $targetRef = &self::$extendMethods;
            $targetRef2 = &self::$pluginsMethods;
            break;
        case 'phpQuery':
            $targetRef = &self::$extendStaticMethods;
            $targetRef2 = &self::$pluginsStaticMethods;
            break;
        default:
            throw new Exception("Unsupported \$target type");
        }
        if (is_string($source)) {
            $source = array($source => $source);
        }
        foreach($source as $method => $callback) {
            if (isset($targetRef[$method])) {
                //                throw new Exception
                self::debug("Duplicate method '{$method}', can\'t extend '{$target}'");
                continue;
            }
            if (isset($targetRef2[$method])) {
                //                throw new Exception
                self::debug(
                    "Duplicate method '{$method}' from plugin '{$targetRef2[$method]}',"
                    ." can\'t extend '{$target}'"
                );
                continue;
            }
            $targetRef[$method] = $callback;
        }
        return true;
    }
199840
private function copySource(TranslationValueInterface $source, WritableTranslationValueInterface $target): void
    {
        if (self::DO_NOT_COPY === $this->copySource) {
            return;
        }

        if (($oldValue = $target->getSource()) === ($newValue = $source->getSource())) {
            $this->logger->log(
                $this->logLevel,
                '{key}: Source is same, no need to update.',
                ['key' => $target->getKey(), 'old' => $oldValue, 'new' => $newValue]
            );
            return;
        }

        if ((self::COPY_IF_EMPTY === $this->copySource) && !$target->isSourceEmpty()) {
            $this->logger->log(
                $this->logLevel,
                '{key}: Source is not empty, no need to update.',
                ['key' => $target->getKey(), 'old' => $oldValue, 'new' => $newValue]
            );

            return;
        }

        $this->logger->log(
            LogLevel::NOTICE,
            '{key}: Updating source value.',
            ['key' => $target->getKey(), 'old' => $oldValue, 'new' => $newValue]
        );

        if ($this->dryRun) {
            return;
        }

        $target->setSource($newValue);
    }
797328
public function hasInSource( $key, $source )
	{
		$source	= strtoupper( $source );
		return isset( $this->sources[$source][$key] );
	}
46499
public static function addTo( &$source, $key, $subKey, $value = null )
    {
        $_target = static::clean( static::get( $source, $key, array() ) );
        static::set( $_target, $subKey, $value );
        static::set( $source, $key, $_target );

        return $_target;
    }
178181
public static function move($source, $target)
    {
        if (!file_exists($source) || !is_dir($source)) {
            // Rename fails if source folder does not exist.
            throw new \RuntimeException('Cannot move non-existing folder.');
        }

        // Don't do anything if the source is the same as the new target
        if ($source === $target) {
            return;
        }

        if (file_exists($target)) {
            // Rename fails if target folder exists.
            throw new \RuntimeException('Cannot move files to existing folder/file.');
        }

        // Make sure that path to the target exists before moving.
        self::create(dirname($target));

        // Silence warnings (chmod failed etc).
        @rename($source, $target);

        // Rename function can fail while still succeeding, so let's check if the folder exists.
        if (!file_exists($target) || !is_dir($target)) {
            // In some rare cases rename() creates file, not a folder. Get rid of it.
            if (file_exists($target)) {
                @unlink($target);
            }
            // Rename doesn't support moving folders across filesystems. Use copy instead.
            self::copy($source, $target);
            self::delete($source);
        }

        // Make sure that the change will be detected when caching.
        @touch(dirname($source));
        @touch(dirname($target));
        @touch($target);
    }
1369864
public function copyFiles($source, $target, $files)
    {
        foreach ($files as $file) {
            $this->copyFile($source, $target, $file);
        }
    }
684864
private function synchronizeItems(OrderItemInterface $source, OrderItemInterface $target)
    {
        $accessor = PropertyAccess::createPropertyAccessor();
        foreach (array('designation', 'reference', 'price', 'weight', 'tax') as $property) {
            $value = $accessor->getValue($source, $property);
            if ($accessor->getValue($target, $property) != $value) {
                $accessor->setValue($target, $property, $value);
            }
        }
    }
524957
public function compress($source, $target = '')
    {
        $target = $target ?: $source.'.zip';

        if ($this->zip->open($target, \ZipArchive::OVERWRITE | \ZipArchive::CREATE) === false) {
            return false;
        }

        if ($this->zip->addFile($source, basename($source)) === false) {
            $this->zip->close();

            return false;
        }

        return $this->zip->close();
    }
556956
public function copyDir($source, $target, $dir)
    {
        $this->mkDir($target);
        $serverOs = (new \Zest\Common\OperatingSystem())->get();
        $command = ($serverOs === 'Windows') ? 'xcopy ' : 'cp -r ';
        if (is_dir($source.$dir)) {
            shell_exec($command.$source.$dir.' '.$target);
        }
    }
1131736
public function export( $key, $target, $ttl = null ) {
		$filename = $this->has( $key, $ttl );

		if ( $filename && $this->ensure_dir_exists( dirname( $target ) ) ) {
			return copy( $filename, $target );
		}

		return false;
	}
839299
protected static function mergeObjects(stdClass &$target, stdClass ...$sources): void
    {
        foreach ($sources as $source) {
            foreach ($source as $key => $value) {
                if (str_starts_with($key, 'i__')) {
                    continue;
                }

                if (isset($target->$key) && is_object($value) && is_object($target->$key)) {
                    static::mergeObjects($target->$key, $value);
                } else {
                    $target->$key = $value;
                }
            }
        }
    }