Kahlan\Dir\Dir::copy PHP Method

copy() public static method

Copies a directory.
public static copy ( array | string $path, string $dest, array $options = [] ) : array
$path array | string Source directory.
$dest string Destination directory.
$options array Scanning options. Possible values are: -`'mode'` _integer_ : Mode used for directory creation. -`'childrenOnly'` _boolean_ : Excludes parent directory if `true`. -`'followSymlinks'` _boolean_ : Follows Symlinks if `true`. -`'recursive'` _boolean_ : Scans recursively if `true`.
return array
    public static function copy($path, $dest, $options = [])
    {
        $defaults = ['mode' => 0755, 'childrenOnly' => false, 'followSymlinks' => true, 'recursive' => true];
        $options += $defaults;
        $options['type'] = [];
        $options['skipDots'] = true;
        $options['leavesOnly'] = false;
        $options['iterator'] = RecursiveIteratorIterator::SELF_FIRST;
        unset($options['include']);
        unset($options['exclude']);
        $sources = (array) $path;
        if (!is_dir($dest)) {
            throw new Exception("Unexisting destination path `{$dest}`.");
        }
        foreach ($sources as $path) {
            static::_copy($path, $dest, $options);
        }
    }

Usage Example

Ejemplo n.º 1
0
             } else {
                 expect(file_exists($this->tmpDir . $target))->toBe(true);
             }
         }
     });
     it("throws an exception if the destination directory doesn't exists", function () {
         $closure = function () {
             Dir::copy('spec/Fixture/Dir', 'Unexisting/Folder');
         };
         expect($closure)->toThrow(new Exception("Unexisting destination path `Unexisting/Folder`."));
     });
 });
 describe("::remove()", function () {
     it("removes a directory recursively", function () {
         $this->tmpDir = Dir::tempnam(sys_get_temp_dir(), 'spec');
         Dir::copy('spec/Fixture/Dir', $this->tmpDir);
         $paths = Dir::scan('spec/Fixture/Dir');
         Dir::remove($this->tmpDir);
         foreach ($paths as $path) {
             $target = preg_replace('~^spec~', '', $path);
             expect(file_exists($this->tmpDir . $target))->toBe(false);
         }
         expect(file_exists($this->tmpDir))->toBe(false);
     });
 });
 describe("::make()", function () {
     beforeEach(function () {
         $this->umask = umask(0);
         $this->tmpDir = Dir::tempnam(sys_get_temp_dir(), 'spec');
     });
     afterEach(function () {