Skip to content
This repository has been archived by the owner on Feb 25, 2020. It is now read-only.

Commit

Permalink
Merge pull request #24 from vool/master
Browse files Browse the repository at this point in the history
Add addString() create file in zip by content and filename
  • Loading branch information
Nils Plaschke committed Nov 25, 2014
2 parents 5538385 + 4a3bf3d commit 9c5660c
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ get the content of a file in the zip. This will return the content or false.
add a string or an array of files to the zip
You can name files or folder, all files in the folder then will be added.

**addString($filename, $content)**

add a file to the zip by specifying a name and content as strings


**getStatus()**

Expand Down
12 changes: 12 additions & 0 deletions src/Chumper/Zipper/Repositories/ZipRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,18 @@ public function addFile($pathToFile, $pathInArchive)
{
$this->archive->addFile($pathToFile, $pathInArchive);
}

/**
* Add a file to the opened Archive using its contents
*
* @param $name
* @param $content
* @return void
*/
public function addFromString($name, $content)
{
$this->archive->addFromString($name, $content);
}

/**
* Remove a file permanently from the Archive
Expand Down
27 changes: 27 additions & 0 deletions src/Chumper/Zipper/Zipper.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,21 @@ public function add($pathToAdd)

return $this;
}

/**
* Add a file to the zip using its contents
*
* @param $filename string The name of the file to create
* @param $content string The file contents
* @return $this Zipper instance
*/
public function addString($filename, $content)
{
$this->addFromString($filename, $content);

return $this;
}


/**
* Gets the status of the zip.
Expand Down Expand Up @@ -366,6 +381,18 @@ private function addFile($pathToAdd)

$this->repository->addFile($pathToAdd, $this->getInternalPath() . $file_name);
}

/**
* Add the file to the zip from content
*
* @param $filename
* @param $content
*/
private function addFromString($filename, $content)
{
$this->repository->addFromString($this->getInternalPath() . $filename, $content);
}


/**
* @param $path
Expand Down

0 comments on commit 9c5660c

Please sign in to comment.