Chumper\Zipper\Zipper::add PHP Method

add() public method

Add one or multiple files to the zip.
public add ( $pathToAdd, $fileName = null )
$pathToAdd array|string An array or string of files and folders to add
    public function add($pathToAdd, $fileName = null)
    {
        if (is_array($pathToAdd)) {
            foreach ($pathToAdd as $dir) {
                $this->add($dir);
            }
        } else {
            if ($this->file->isFile($pathToAdd)) {
                if ($fileName) {
                    $this->addFile($pathToAdd, $fileName);
                } else {
                    $this->addFile($pathToAdd);
                }
            } else {
                $this->addDir($pathToAdd);
            }
        }
        return $this;
    }

Usage Example

Beispiel #1
0
 public function testListFiles()
 {
     // testing empty file
     $this->file->shouldReceive('isFile')->with('foo.file')->andReturn(true);
     $this->file->shouldReceive('isFile')->with('bar.file')->andReturn(true);
     $this->assertEquals(array(), $this->archive->listFiles());
     // testing not empty file
     $this->archive->add('foo.file');
     $this->archive->add('bar.file');
     $this->assertEquals(array('foo.file', 'bar.file'), $this->archive->listFiles());
     // testing with a empty sub dir
     $this->file->shouldReceive('isFile')->with('/path/to/subDirEmpty')->andReturn(false);
     $this->file->shouldReceive('files')->with('/path/to/subDirEmpty')->andReturn(array());
     $this->file->shouldReceive('directories')->with('/path/to/subDirEmpty')->andReturn(array());
     $this->archive->folder('subDirEmpty')->add('/path/to/subDirEmpty');
     $this->assertEquals(array('foo.file', 'bar.file'), $this->archive->listFiles());
     // testing with a not empty sub dir
     $this->file->shouldReceive('isFile')->with('/path/to/subDir')->andReturn(false);
     $this->file->shouldReceive('isFile')->with('sub.file')->andReturn(true);
     $this->file->shouldReceive('files')->with('/path/to/subDir')->andReturn(array('sub.file'));
     $this->file->shouldReceive('directories')->with('/path/to/subDir')->andReturn(array());
     $this->archive->folder('subDir')->add('/path/to/subDir');
     $this->assertEquals(array('foo.file', 'bar.file', 'subDir/sub.file'), $this->archive->listFiles());
 }
All Usage Examples Of Chumper\Zipper\Zipper::add